]>
git.wh0rd.org - tt-rss.git/blob - classes/ccache.php
9a6f14f3d867fad5f65d94fef0a549a339d95a47
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
122 (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))");
123 $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
125 while ($line = $sth->fetch()) {
126 CCache
::update($line["id"], $owner_uid, false, false);
130 $sth = $pdo->prepare("SELECT SUM(value) AS sv
131 FROM ttrss_counters_cache, ttrss_feeds
132 WHERE id = feed_id AND
133 (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND
134 ttrss_counters_cache.owner_uid = :uid AND
135 ttrss_feeds.owner_uid = :uid");
136 $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
137 $row = $sth->fetch();
139 $unread = (int) $row["sv"];
142 $unread = (int) Feeds
::getFeedArticles($feed_id, $is_cat, true, $owner_uid);
145 $pdo->beginTransaction();
147 $sth = $pdo->prepare("SELECT feed_id FROM $table
148 WHERE owner_uid = ? AND feed_id = ? LIMIT 1");
149 $sth->execute([$owner_uid, $feed_id]);
153 $sth = $pdo->prepare("UPDATE $table SET
154 value = ?, updated = NOW() WHERE
155 feed_id = ? AND owner_uid = ?");
157 $sth->execute([$unread, $feed_id, $owner_uid]);
160 $sth = $pdo->prepare("INSERT INTO $table
161 (feed_id, value, owner_uid, updated)
164 $sth->execute([$feed_id, $unread, $owner_uid]);
169 if ($feed_id > 0 && $prev_unread != $unread) {
173 /* Update parent category */
177 $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds
178 WHERE owner_uid = ? AND id = ?");
179 $sth->execute([$owner_uid, $feed_id]);
181 if ($row = $sth->fetch()) {
182 CCache
::update($row["cat_id"], $owner_uid, true, true, true);
186 } else if ($feed_id < 0) {
187 CCache
::update_all($owner_uid);