From d4327bcdea42354bcb9200915964f9e3608a1a31 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Mon, 27 Jul 2015 23:49:39 +0200 Subject: [PATCH 1/2] Use the date specified by the items as the date of the last entry --- daos/mysql/Sources.php | 8 ++++---- helpers/ContentLoader.php | 17 ++++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/daos/mysql/Sources.php b/daos/mysql/Sources.php index 706e3f3f62..d8b8c7c023 100644 --- a/daos/mysql/Sources.php +++ b/daos/mysql/Sources.php @@ -108,20 +108,20 @@ public function error($id, $error) { * * @return void * @param int $id the source id - * @param boolean newPostAdded true or false depending on whether a post was added + * @param int $lastEntry timestamp of the newest item or NULL when no items were added */ - public function saveLastUpdate($id, $newPostAdded) { + public function saveLastUpdate($id, $lastEntry) { \F3::get('db')->exec('UPDATE '.\F3::get('db_prefix').'sources SET lastupdate=:lastupdate WHERE id=:id', array( ':id' => $id, ':lastupdate' => time() )); - if ($newPostAdded == TRUE) { + if ($lastEntry !== null) { \F3::get('db')->exec('UPDATE '.\F3::get('db_prefix').'sources SET lastentry=:lastentry WHERE id=:id', array( ':id' => $id, - ':lastentry' => time() + ':lastentry' => $lastEntry )); } diff --git a/helpers/ContentLoader.php b/helpers/ContentLoader.php index 9abdcd1436..087394517c 100644 --- a/helpers/ContentLoader.php +++ b/helpers/ContentLoader.php @@ -58,10 +58,10 @@ public function update() { */ public function fetch($source) { - $newPostAdded = FALSE; + $lastEntry = $source['lastentry']; // at least 20 seconds wait until next update of a given source - $this->updateSource($source, $newPostAdded); + $this->updateSource($source, null); if(time() - $source['lastupdate'] < 20) return; @@ -188,7 +188,7 @@ public function fetch($source) { \F3::get('logger')->log('Memory usage: '.memory_get_usage(), \DEBUG); \F3::get('logger')->log('Memory peak usage: '.memory_get_peak_usage(), \DEBUG); - $newPostAdded = TRUE; + $lastEntry = max($lastEntry, $itemDate->getTimestamp()); } // destroy feed object (prevent memory issues) @@ -196,7 +196,7 @@ public function fetch($source) { $spout->destroy(); // remove previous errors and set last update timestamp - $this->updateSource($source, $newPostAdded); + $this->updateSource($source, $lastEntry); } /** @@ -379,16 +379,15 @@ protected function cleanupFiles($type) { /** * Update source (remove previous errors, update last update) * - * @param $source source object - * @param $newPostAdded boolean true or false depending on if a new post was found - * + * @param mixed $source source object + * @param int $lastEntry timestamp of the newest item or NULL when no items were added */ - protected function updateSource($source, $newPostAdded) { + protected function updateSource($source, $lastEntry) { // remove previous error if ( !is_null($source['error']) ) { $this->sourceDao->error($source['id'], ''); } // save last update - $this->sourceDao->saveLastUpdate($source['id'], $newPostAdded); + $this->sourceDao->saveLastUpdate($source['id'], $lastEntry); } } From f5498b6b5863cda46a7edc009bdca36e34ff42fd Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 28 Jul 2015 00:12:35 +0200 Subject: [PATCH 2/2] Add missing lastentry to daos\mysql\Sources::getByLastUpdate() --- daos/mysql/Sources.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daos/mysql/Sources.php b/daos/mysql/Sources.php index d8b8c7c023..af596f02fd 100644 --- a/daos/mysql/Sources.php +++ b/daos/mysql/Sources.php @@ -134,7 +134,7 @@ public function saveLastUpdate($id, $lastEntry) { * @return mixed all sources */ public function getByLastUpdate() { - $ret = \F3::get('db')->exec('SELECT id, title, tags, spout, params, filter, error, lastupdate FROM '.\F3::get('db_prefix').'sources ORDER BY lastupdate ASC'); + $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'); $spoutLoader = new \helpers\SpoutLoader(); for($i=0;$iget( $ret[$i]['spout'] );