purge_feed: add more debugging output

This commit is contained in:
Andrew Dolgov 2020-12-15 08:50:01 +03:00
parent 9b7338e807
commit f05f9b4252
1 changed files with 50 additions and 48 deletions

View File

@ -2104,12 +2104,10 @@ class Feeds extends Handler_Protected {
/** /**
* Purge a feed old posts. * Purge a feed old posts.
* *
* @param mixed $link A database connection.
* @param mixed $feed_id The id of the purged feed. * @param mixed $feed_id The id of the purged feed.
* @param mixed $purge_interval Olderness of purged posts. * @param mixed $purge_interval Olderness of purged posts.
* @param boolean $debug Set to True to enable the debug. False by default.
* @access public * @access public
* @return void * @return mixed
*/ */
static function purge_feed($feed_id, $purge_interval) { static function purge_feed($feed_id, $purge_interval) {
@ -2117,63 +2115,68 @@ class Feeds extends Handler_Protected {
$pdo = Db::pdo(); $pdo = Db::pdo();
$owner_uid = false;
$rows_deleted = 0;
$sth = $pdo->prepare("SELECT owner_uid FROM ttrss_feeds WHERE id = ?"); $sth = $pdo->prepare("SELECT owner_uid FROM ttrss_feeds WHERE id = ?");
$sth->execute([$feed_id]); $sth->execute([$feed_id]);
$owner_uid = false;
if ($row = $sth->fetch()) { if ($row = $sth->fetch()) {
$owner_uid = $row["owner_uid"]; $owner_uid = $row["owner_uid"];
}
if ($purge_interval == -1 || !$purge_interval) { if (FORCE_ARTICLE_PURGE != 0) {
return; Debug::log("purge_feed: FORCE_ARTICLE_PURGE is set, overriding interval to " . FORCE_ARTICLE_PURGE);
} $purge_unread = true;
$purge_interval = FORCE_ARTICLE_PURGE;
} else {
$purge_unread = get_pref("PURGE_UNREAD_ARTICLES", $owner_uid, false);
}
if (!$owner_uid) return; $purge_interval = (int) $purge_interval;
if (FORCE_ARTICLE_PURGE == 0) { Debug::log("purge_feed: interval $purge_interval days for feed $feed_id, owner: $owner_uid, purge unread: $purge_unread");
$purge_unread = get_pref("PURGE_UNREAD_ARTICLES",
$owner_uid, false);
} else {
$purge_unread = true;
$purge_interval = FORCE_ARTICLE_PURGE;
}
if (!$purge_unread) if ($purge_interval <= 0) {
$query_limit = " unread = false AND "; Debug::log("purge_feed: purging disabled for this feed, nothing to do.");
else return;
$query_limit = ""; }
$purge_interval = (int) $purge_interval; if (!$purge_unread)
$query_limit = " unread = false AND ";
else
$query_limit = "";
if (DB_TYPE == "pgsql") { if (DB_TYPE == "pgsql") {
$sth = $pdo->prepare("DELETE FROM ttrss_user_entries $sth = $pdo->prepare("DELETE FROM ttrss_user_entries
USING ttrss_entries USING ttrss_entries
WHERE ttrss_entries.id = ref_id AND WHERE ttrss_entries.id = ref_id AND
marked = false AND marked = false AND
feed_id = ? AND feed_id = ? AND
$query_limit $query_limit
ttrss_entries.date_updated < NOW() - INTERVAL '$purge_interval days'"); ttrss_entries.date_updated < NOW() - INTERVAL '$purge_interval days'");
$sth->execute([$feed_id]); $sth->execute([$feed_id]);
} else {
$sth = $pdo->prepare("DELETE FROM ttrss_user_entries
USING ttrss_user_entries, ttrss_entries
WHERE ttrss_entries.id = ref_id AND
marked = false AND
feed_id = ? AND
$query_limit
ttrss_entries.date_updated < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)");
$sth->execute([$feed_id]);
}
$rows_deleted = $sth->rowCount();
Debug::log("purge_feed: processed $feed_id: deleted $rows_deleted articles");
} else { } else {
$sth = $pdo->prepare("DELETE FROM ttrss_user_entries Debug::log("purge_feed: owner of $feed_id not found");
USING ttrss_user_entries, ttrss_entries
WHERE ttrss_entries.id = ref_id AND
marked = false AND
feed_id = ? AND
$query_limit
ttrss_entries.date_updated < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)");
$sth->execute([$feed_id]);
} }
$rows = $sth->rowCount(); return $rows_deleted;
Debug::log("Purged feed $feed_id ($purge_interval): deleted $rows articles");
return $rows;
} }
static function feed_purge_interval($feed_id) { static function feed_purge_interval($feed_id) {
@ -2188,11 +2191,10 @@ class Feeds extends Handler_Protected {
$purge_interval = $row["purge_interval"]; $purge_interval = $row["purge_interval"];
$owner_uid = $row["owner_uid"]; $owner_uid = $row["owner_uid"];
if ($purge_interval == 0) $purge_interval = get_pref( if ($purge_interval == 0)
'PURGE_OLD_DAYS', $owner_uid); $purge_interval = get_pref('PURGE_OLD_DAYS', $owner_uid, false);
return $purge_interval; return $purge_interval;
} else { } else {
return -1; return -1;
} }