feed update: introduce reference point

This commit is contained in:
2021-07-06 22:48:18 +02:00
parent af3e44e476
commit 95531b4691
3 changed files with 28 additions and 17 deletions

View File

@@ -224,7 +224,7 @@ class Spot extends Main
$oEmail->oTemplate->setTag('date_time', 'time:'.$asLastMessage['unix_time'], 'd/m/Y, H:i');
//Add latest news feed
$asNews = $this->getNewsFeed(0, true);
$asNews = $this->getNewsFeed(0, 0, true);
$iPostCount = 0;
foreach($asNews as $asPost) {
if($asPost['type'] != 'message') {
@@ -425,7 +425,7 @@ class Spot extends Main
if($sTimeZone != '') $asData['formatted_time_local'] = $this->getTimeFormat($iTime, $sTimeZone);
}
public function getNewsFeed($iChunk=0, $bInternal=false)
public function getNewsFeed($iChunk=0, $iRefTimePoint=0, $bInternal=false)
{
$bHistoMode = ($this->oProject->getMode() == Project::MODE_HISTO);
$asFeeds = array();
@@ -435,7 +435,7 @@ class Spot extends Main
'feed' => $this->getSpotMessages(),
'priority' => 0
),
'media' => array(
'media' => array(
'table' => Media::MEDIA_TABLE,
'feed' => $this->getMedias('posted_on'),
'priority' => 1
@@ -448,25 +448,31 @@ class Spot extends Main
);
foreach($asFeedTypes as $sFeedType=>$asFeedTypeInfo) {
foreach($asFeedTypeInfo['feed'] as $asFeed) {
$sPriority = $asFeedTypeInfo['priority'];
if($bHistoMode) $sPriority = count($asFeedTypes) - 1 - $asFeedTypeInfo['priority'];
$iTableId = $asFeed[Db::getId($asFeedTypeInfo['table'])];
$iId = ($asFeed['unix_time'] * -1).'.'.$sPriority.$iTableId;
$asFeeds[$iId] = $asFeed;
$asFeeds[$iId]['type'] = $sFeedType;
$asFeeds[$iId]['id'] = $iTableId;
//Build unique sorting ID
$iSort = $asFeed['unix_time'].'.'.$asFeedTypeInfo['priority'].$iTableId;
//Build feed (not including new feeds added in between chunk by concurrent access)
if($iChunk == 0 || $iSort <= $iRefTimePoint) {
$asFeeds[$iSort] = $asFeed;
$asFeeds[$iSort]['type'] = $sFeedType;
$asFeeds[$iSort]['id'] = $iTableId;
}
//Build Reference Time Point (latest item extracted by first chunk)
if($iChunk == 0 && $iSort > $iRefTimePoint) $iRefTimePoint = $iSort;
}
}
//Sort by key
if($bHistoMode) krsort($asFeeds);
else ksort($asFeeds);
if($bHistoMode) ksort($asFeeds); //Old first
else krsort($asFeeds); //New first
//Split chunks
$asFeeds = array_slice($asFeeds, $iChunk * self::FEED_CHUNK_SIZE, self::FEED_CHUNK_SIZE);
return $bInternal?$asFeeds:self::getJsonResult(true, '', $asFeeds);
return $bInternal?$asFeeds:self::getJsonResult(true, '', array('ref_id'=>$iRefTimePoint, 'feed' => $asFeeds));
}
public function syncMedias() {