aboutsummaryrefslogtreecommitdiff
path: root/app/models/Feed.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-14 16:22:38 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-14 16:22:38 +0100
commit4af233e1f736eb2256e5e1696418635165467855 (patch)
treeb6c74a3d5de652f8374ffddc9b7b7c25455eb14a /app/models/Feed.php
parent7e8e222c871b7394c770176a63a55d9a8ab2b84d (diff)
Nettoyage des flux plus intelligent
Implémente https://github.com/marienfressinaud/FreshRSS/issues/323 Garde au moins n+10 articles, où n est le nombre d'articles toujours présent dans le flux RSS.
Diffstat (limited to 'app/models/Feed.php')
-rw-r--r--app/models/Feed.php21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/Feed.php b/app/models/Feed.php
index 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 {