]>
git.wh0rd.org - tt-rss.git/blob - classes/ccache.php
3 static function zero_all($owner_uid) {
6 $sth = $pdo->prepare("UPDATE ttrss_counters_cache SET
7 value = 0 WHERE owner_uid = ?");
8 $sth->execute([$owner_uid]);
10 $sth = $pdo->prepare("UPDATE ttrss_cat_counters_cache SET
11 value = 0 WHERE owner_uid = ?");
12 $sth->execute([$owner_uid]);
15 static function remove($feed_id, $owner_uid, $is_cat = false) {
18 $table = "ttrss_counters_cache";
20 $table = "ttrss_cat_counters_cache";
25 $sth = $pdo->prepare("DELETE FROM $table WHERE
26 feed_id = ? AND owner_uid = ?");
27 $sth->execute([$feed_id, $owner_uid]);
31 static function update_all($owner_uid) {
35 if (get_pref('ENABLE_FEED_CATS', $owner_uid)) {
37 $sth = $pdo->prepare("SELECT feed_id FROM ttrss_cat_counters_cache
38 WHERE feed_id > 0 AND owner_uid = ?");
39 $sth->execute([$owner_uid]);
41 while ($line = $sth->fetch()) {
42 CCache
::update($line["feed_id"], $owner_uid, true);
45 /* We have to manually include category 0 */
47 CCache
::update(0, $owner_uid, true);
50 $sth = $pdo->prepare("SELECT feed_id FROM ttrss_counters_cache
51 WHERE feed_id > 0 AND owner_uid = ?");
52 $sth->execute([$owner_uid]);
54 while ($line = $sth->fetch()) {
55 print CCache
::update($line["feed_id"], $owner_uid);
62 static function find($feed_id, $owner_uid, $is_cat = false,
65 if (!is_numeric($feed_id)) return;
68 $table = "ttrss_counters_cache";
70 $table = "ttrss_cat_counters_cache";
75 $sth = $pdo->prepare("SELECT value FROM $table
76 WHERE owner_uid = ? AND feed_id = ?
79 $sth->execute([$owner_uid, $feed_id]);
81 if ($row = $sth->fetch()) {
87 return CCache
::update($feed_id, $owner_uid, $is_cat);
93 static function update($feed_id, $owner_uid, $is_cat = false,
94 $update_pcat = true, $pcat_fast = false) {
96 if (!is_numeric($feed_id)) return;
98 $prev_unread = CCache
::find($feed_id, $owner_uid, $is_cat, true);
100 /* When updating a label, all we need to do is recalculate feed counters
101 * because labels are not cached */
104 CCache
::update_all($owner_uid);
109 $table = "ttrss_counters_cache";
111 $table = "ttrss_cat_counters_cache";
116 if ($is_cat && $feed_id >= 0) {
117 /* Recalculate counters for child feeds */
120 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds
121 WHERE owner_uid = :uid AND cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)");
122 $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
124 while ($line = $sth->fetch()) {
125 CCache
::update($line["id"], $owner_uid, false, false);
129 $sth = $pdo->prepare("SELECT SUM(value) AS sv
130 FROM ttrss_counters_cache, ttrss_feeds
131 WHERE id = feed_id AND
132 cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL) AND
133 ttrss_counters_cache.owner_uid = :uid AND
134 ttrss_feeds.owner_uid = :uid");
135 $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
136 $row = $sth->fetch();
138 $unread = (int) $row["sv"];
141 $unread = (int) Feeds
::getFeedArticles($feed_id, $is_cat, true, $owner_uid);
144 $pdo->beginTransaction();
146 $sth = $pdo->prepare("SELECT feed_id FROM $table
147 WHERE owner_uid = ? AND feed_id = ? LIMIT 1");
148 $sth->execute([$owner_uid, $feed_id]);
152 $sth = $pdo->prepare("UPDATE $table SET
153 value = ?, updated = NOW() WHERE
154 feed_id = ? AND owner_uid = ?");
156 $sth->execute([$unread, $feed_id, $owner_uid]);
159 $sth = $pdo->prepare("INSERT INTO $table
160 (feed_id, value, owner_uid, updated)
163 $sth->execute([$feed_id, $unread, $owner_uid]);
168 if ($feed_id > 0 && $prev_unread != $unread) {
172 /* Update parent category */
176 $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds
177 WHERE owner_uid = ? AND id = ?");
178 $sth->execute([$owner_uid, $feed_id]);
180 if ($row = $sth->fetch()) {
181 CCache
::update($row["cat_id"], $owner_uid, true, true, true);
185 } else if ($feed_id < 0) {
186 CCache
::update_all($owner_uid);