diff options
| author | 2013-12-14 16:22:38 +0100 | |
|---|---|---|
| committer | 2013-12-14 16:22:38 +0100 | |
| commit | 4af233e1f736eb2256e5e1696418635165467855 (patch) | |
| tree | b6c74a3d5de652f8374ffddc9b7b7c25455eb14a /app/models | |
| parent | 7e8e222c871b7394c770176a63a55d9a8ab2b84d (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')
| -rwxr-xr-x | app/models/Entry.php | 18 | ||||
| -rw-r--r-- | app/models/Feed.php | 21 |
2 files changed, 21 insertions, 18 deletions
diff --git a/app/models/Entry.php b/app/models/Entry.php index 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.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 { |
