A free, self-hostable news aggregator…
Nettoyage des flux plus intelligent
Alexandre Alapetite4af233e1f736
diff --git a/app/controllers/feedController.php b/app/controllers/feedController.phpindex a38614b3d..24b8627ff 100755--- a/app/controllers/feedController.php+++ b/app/controllers/feedController.php@@ -197,14 +197,6 @@ class feedController extends ActionController {// on calcule la date des articles les plus anciens qu'on accepte$nb_month_old = $this->view->conf->oldEntries ();$date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old);- if (rand(0, 30) === 1) {- $nb = $entryDAO->cleanOldEntries ($date_min);- Minz_Log::record ($nb . ' old entries cleaned.', Minz_Log::DEBUG);- if ($nb > 0) {- $nb = $feedDAO->updateCachedValues ();- Minz_Log::record ($nb . ' cached values updated.', Minz_Log::DEBUG);- }- }$i = 0;$flux_update = 0;@@ -235,6 +227,11 @@ class feedController extends ActionController {}}+ if ((!$feed->keepHistory()) && (rand(0, 30) === 1)) {+ $nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, count($entries) + 10);+ Minz_Log::record ($nb . ' old entries cleaned in feed ' . $feed->id (), Minz_Log::DEBUG);+ }+// on indique que le flux vient d'être mis à jour en BDD$feedDAO->updateLastUpdate ($feed->id ());$feedDAO->commit ();diff --git a/app/models/Entry.php b/app/models/Entry.phpindex 103a90706..328a7da2e 100755--- a/app/models/Entry.php+++ b/app/models/Entry.php@@ -423,24 +423,6 @@ class EntryDAO extends Model_pdo {}}- public function cleanOldEntries ($date_min) {- $sql = 'DELETE e.* FROM `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '- . 'WHERE e.id <= ? AND e.is_favorite = 0 AND f.keep_history = 0';- $stm = $this->bd->prepare ($sql);-- $values = array (- $date_min . '000000'- );-- if ($stm && $stm->execute ($values)) {- return $stm->rowCount();- } else {- $info = $stm->errorInfo();- Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);- return false;- }- }-public function searchByGuid ($feed_id, $id) {// un guid est unique pour un flux donné$sql = 'SELECT id, guid, title, author, UNCOMPRESS(content_bin) AS content, link, date, is_read, is_favorite, id_feed, tags 'diff --git a/app/models/Feed.php b/app/models/Feed.phpindex 043956f71..4acf47744 100644--- a/app/models/Feed.php+++ b/app/models/Feed.php@@ -598,6 +598,27 @@ class FeedDAO extends Model_pdo {$this->bd->commit ();return $affected;}++ public function cleanOldEntries ($id, $date_min, $keep = 15) { //Remember to call updateLastUpdate($id) just after+ $sql = 'DELETE e.* FROM `' . $this->prefix . 'entry` e '+ . 'WHERE e.id_feed = :id_feed AND e.id <= :id_max AND e.is_favorite = 0 AND e.id NOT IN '+ . '(SELECT id FROM (SELECT e2.id FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed = :id_feed ORDER BY id DESC LIMIT :keep) keep)'; //Double select because of: MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'+ $stm = $this->bd->prepare ($sql);++ $id_max = intval($date_min) . '000000';++ $stm->bindParam(':id_feed', $id, PDO::PARAM_INT);+ $stm->bindParam(':id_max', $id_max, PDO::PARAM_INT);+ $stm->bindParam(':keep', $keep, PDO::PARAM_INT);++ if ($stm && $stm->execute ()) {+ return $stm->rowCount();+ } else {+ $info = $stm->errorInfo();+ Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);+ return false;+ }+ }}class HelperFeed {