Skip to content

Commit 18a1053

Browse files
committed
Merge pull request #690 from PhrozenByte/enhancement/ImproveLastEntry
Use the date specified by the items as the date of the last entry
2 parents 1270597 + f5498b6 commit 18a1053

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

daos/mysql/Sources.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,20 @@ public function error($id, $error) {
108108
*
109109
* @return void
110110
* @param int $id the source id
111-
* @param boolean newPostAdded true or false depending on whether a post was added
111+
* @param int $lastEntry timestamp of the newest item or NULL when no items were added
112112
*/
113-
public function saveLastUpdate($id, $newPostAdded) {
113+
public function saveLastUpdate($id, $lastEntry) {
114114
\F3::get('db')->exec('UPDATE '.\F3::get('db_prefix').'sources SET lastupdate=:lastupdate WHERE id=:id',
115115
array(
116116
':id' => $id,
117117
':lastupdate' => time()
118118
));
119119

120-
if ($newPostAdded == TRUE) {
120+
if ($lastEntry !== null) {
121121
\F3::get('db')->exec('UPDATE '.\F3::get('db_prefix').'sources SET lastentry=:lastentry WHERE id=:id',
122122
array(
123123
':id' => $id,
124-
':lastentry' => time()
124+
':lastentry' => $lastEntry
125125
));
126126
}
127127

@@ -134,7 +134,7 @@ public function saveLastUpdate($id, $newPostAdded) {
134134
* @return mixed all sources
135135
*/
136136
public function getByLastUpdate() {
137-
$ret = \F3::get('db')->exec('SELECT id, title, tags, spout, params, filter, error, lastupdate FROM '.\F3::get('db_prefix').'sources ORDER BY lastupdate ASC');
137+
$ret = \F3::get('db')->exec('SELECT id, title, tags, spout, params, filter, error, lastupdate, lastentry FROM '.\F3::get('db_prefix').'sources ORDER BY lastupdate ASC');
138138
$spoutLoader = new \helpers\SpoutLoader();
139139
for($i=0;$i<count($ret);$i++)
140140
$ret[$i]['spout_obj'] = $spoutLoader->get( $ret[$i]['spout'] );

helpers/ContentLoader.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public function update() {
5858
*/
5959
public function fetch($source) {
6060

61-
$newPostAdded = FALSE;
61+
$lastEntry = $source['lastentry'];
6262

6363
// at least 20 seconds wait until next update of a given source
64-
$this->updateSource($source, $newPostAdded);
64+
$this->updateSource($source, null);
6565
if(time() - $source['lastupdate'] < 20)
6666
return;
6767

@@ -188,15 +188,15 @@ public function fetch($source) {
188188
\F3::get('logger')->log('Memory usage: '.memory_get_usage(), \DEBUG);
189189
\F3::get('logger')->log('Memory peak usage: '.memory_get_peak_usage(), \DEBUG);
190190

191-
$newPostAdded = TRUE;
191+
$lastEntry = max($lastEntry, $itemDate->getTimestamp());
192192
}
193193

194194
// destroy feed object (prevent memory issues)
195195
\F3::get('logger')->log('destroy spout object', \DEBUG);
196196
$spout->destroy();
197197

198198
// remove previous errors and set last update timestamp
199-
$this->updateSource($source, $newPostAdded);
199+
$this->updateSource($source, $lastEntry);
200200
}
201201

202202
/**
@@ -379,16 +379,15 @@ protected function cleanupFiles($type) {
379379
/**
380380
* Update source (remove previous errors, update last update)
381381
*
382-
* @param $source source object
383-
* @param $newPostAdded boolean true or false depending on if a new post was found
384-
*
382+
* @param mixed $source source object
383+
* @param int $lastEntry timestamp of the newest item or NULL when no items were added
385384
*/
386-
protected function updateSource($source, $newPostAdded) {
385+
protected function updateSource($source, $lastEntry) {
387386
// remove previous error
388387
if ( !is_null($source['error']) ) {
389388
$this->sourceDao->error($source['id'], '');
390389
}
391390
// save last update
392-
$this->sourceDao->saveLastUpdate($source['id'], $newPostAdded);
391+
$this->sourceDao->saveLastUpdate($source['id'], $lastEntry);
393392
}
394393
}

0 commit comments

Comments
 (0)