]> git.wh0rd.org Git - tt-rss.git/commitdiff
update_daemon_common: purge inactive/not updated feeds
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 26 Feb 2013 12:16:04 +0000 (16:16 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 26 Feb 2013 12:16:04 +0000 (16:16 +0400)
include/functions.php
include/rssfuncs.php

index 72d86e0a7c5be273be5aff1990950c8a271cce1a..572720787438248de478cc643d2a8032887385ee 100644 (file)
                if ($debug) {
                        _debug("Purged feed $feed_id ($purge_interval): deleted $rows articles");
                }
+
+               return $rows;
        } // function purge_feed
 
        function feed_purge_interval($link, $feed_id) {
index c3ac1073015f984f943870f316aa01177ec00d2a..b82a872f4aa4d7e886aef1b908469fe9b1ca8c76 100644 (file)
                // Send feed digests by email if needed.
                send_headlines_digests($link, $debug);
 
+               // Purge feeds with stale data OR not being updated for a while to keep DB size down
+
+               if ($debug) _debug("Purging inactive feeds...");
+
+               if (DB_TYPE == "pgsql") {
+                       $interval_qpart = "NOW() - INTERVAL '1 month'";
+               } else {
+                       $interval_qpart = "DATE_SUB(NOW(), INTERVAL 1 MONTH)";
+               }
+
+               $result = db_query($link, "SELECT id, feed_url FROM ttrss_feeds WHERE
+                                       (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
+                                               ttrss_entries.id = ref_id AND
+                                               ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart OR
+                                       last_updated < $interval_qpart");
+
+               $feeds_purged = 0;
+               $articles_removed = 0;
+
+               while ($line = db_fetch_assoc($result)) {
+                       $articles_removed += purge_feed($link, $line["id"], 0, false);
+                       ++$feeds_purged;
+               }
+
+               if ($debug && $articles_removed > 0)
+                       _debug(sprintf("Purged %d feeds (%d articles).", $feeds_purged,
+                               $articles_removed));
+
        } // function update_daemon_common
 
        // ignore_daemon is not used