X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=classes%2Fccache.php;h=9c5547e7d88a6c2346ca903ebd1cf54bbdedff42;hb=3a0292303e453f38204279b5d1c978a4b9c367e9;hp=9a6f14f3d867fad5f65d94fef0a549a339d95a47;hpb=cc9450c309dbeedadaf23a8140520ab3726e3206;p=tt-rss.git diff --git a/classes/ccache.php b/classes/ccache.php index 9a6f14f3..9c5547e7 100644 --- a/classes/ccache.php +++ b/classes/ccache.php @@ -14,6 +14,8 @@ class CCache { static function remove($feed_id, $owner_uid, $is_cat = false) { + $feed_id = (int) $feed_id; + if (!$is_cat) { $table = "ttrss_counters_cache"; } else { @@ -62,7 +64,12 @@ class CCache { static function find($feed_id, $owner_uid, $is_cat = false, $no_update = false) { - if (!is_numeric($feed_id)) return; + // "" (null) is valid and should be cast to 0 (uncategorized) + // everything else i.e. tags are not + if (!is_numeric($feed_id) && $feed_id) + return; + + $feed_id = (int) $feed_id; if (!$is_cat) { $table = "ttrss_counters_cache"; @@ -93,7 +100,12 @@ class CCache { static function update($feed_id, $owner_uid, $is_cat = false, $update_pcat = true, $pcat_fast = false) { - if (!is_numeric($feed_id)) return; + // "" (null) is valid and should be cast to 0 (uncategorized) + // everything else i.e. tags are not + if (!is_numeric($feed_id) && $feed_id) + return; + + $feed_id = (int) $feed_id; $prev_unread = CCache::find($feed_id, $owner_uid, $is_cat, true); @@ -118,18 +130,18 @@ class CCache { if (!$pcat_fast) { $sth = $pdo->prepare("SELECT id FROM ttrss_feeds - WHERE owner_uid = :uid AND + WHERE owner_uid = :uid AND (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))"); $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]); while ($line = $sth->fetch()) { - CCache::update($line["id"], $owner_uid, false, false); + CCache::update((int)$line["id"], $owner_uid, false, false); } } $sth = $pdo->prepare("SELECT SUM(value) AS sv FROM ttrss_counters_cache, ttrss_feeds - WHERE id = feed_id AND + WHERE id = feed_id AND (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND ttrss_counters_cache.owner_uid = :uid AND ttrss_feeds.owner_uid = :uid"); @@ -142,7 +154,13 @@ class CCache { $unread = (int) Feeds::getFeedArticles($feed_id, $is_cat, true, $owner_uid); } - $pdo->beginTransaction(); + $tr_in_progress = false; + + try { + $pdo->beginTransaction(); + } catch (Exception $e) { + $tr_in_progress = true; + } $sth = $pdo->prepare("SELECT feed_id FROM $table WHERE owner_uid = ? AND feed_id = ? LIMIT 1"); @@ -164,7 +182,7 @@ class CCache { $sth->execute([$feed_id, $unread, $owner_uid]); } - $pdo->commit(); + if (!$tr_in_progress) $pdo->commit(); if ($feed_id > 0 && $prev_unread != $unread) { @@ -179,7 +197,7 @@ class CCache { $sth->execute([$owner_uid, $feed_id]); if ($row = $sth->fetch()) { - CCache::update($row["cat_id"], $owner_uid, true, true, true); + CCache::update((int)$row["cat_id"], $owner_uid, true, true, true); } } }