]>
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) {
17 $feed_id = (int) $feed_id;
20 $table = "ttrss_counters_cache";
22 $table = "ttrss_cat_counters_cache";
27 $sth = $pdo->prepare("DELETE FROM $table WHERE
28 feed_id = ? AND owner_uid = ?");
29 $sth->execute([$feed_id, $owner_uid]);
33 static function update_all($owner_uid) {
37 if (get_pref('ENABLE_FEED_CATS', $owner_uid)) {
39 $sth = $pdo->prepare("SELECT feed_id FROM ttrss_cat_counters_cache
40 WHERE feed_id > 0 AND owner_uid = ?");
41 $sth->execute([$owner_uid]);
43 while ($line = $sth->fetch()) {
44 CCache
::update($line["feed_id"], $owner_uid, true);
47 /* We have to manually include category 0 */
49 CCache
::update(0, $owner_uid, true);
52 $sth = $pdo->prepare("SELECT feed_id FROM ttrss_counters_cache
53 WHERE feed_id > 0 AND owner_uid = ?");
54 $sth->execute([$owner_uid]);
56 while ($line = $sth->fetch()) {
57 print CCache
::update($line["feed_id"], $owner_uid);
64 static function find($feed_id, $owner_uid, $is_cat = false,
67 // "" (null) is valid and should be cast to 0 (uncategorized)
68 // everything else i.e. tags are not
69 if (!is_numeric($feed_id) && $feed_id)
72 $feed_id = (int) $feed_id;
75 $table = "ttrss_counters_cache";
77 $table = "ttrss_cat_counters_cache";
82 $sth = $pdo->prepare("SELECT value FROM $table
83 WHERE owner_uid = ? AND feed_id = ?
86 $sth->execute([$owner_uid, $feed_id]);
88 if ($row = $sth->fetch()) {
94 return CCache
::update($feed_id, $owner_uid, $is_cat);
100 static function update($feed_id, $owner_uid, $is_cat = false,
101 $update_pcat = true, $pcat_fast = false) {
103 // "" (null) is valid and should be cast to 0 (uncategorized)
104 // everything else i.e. tags are not
105 if (!is_numeric($feed_id) && $feed_id)
108 $feed_id = (int) $feed_id;
110 $prev_unread = CCache
::find($feed_id, $owner_uid, $is_cat, true);
112 /* When updating a label, all we need to do is recalculate feed counters
113 * because labels are not cached */
116 CCache
::update_all($owner_uid);
121 $table = "ttrss_counters_cache";
123 $table = "ttrss_cat_counters_cache";
128 if ($is_cat && $feed_id >= 0) {
129 /* Recalculate counters for child feeds */
132 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds
133 WHERE owner_uid = :uid AND
134 (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))");
135 $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
137 while ($line = $sth->fetch()) {
138 CCache
::update((int)$line["id"], $owner_uid, false, false);
142 $sth = $pdo->prepare("SELECT SUM(value) AS sv
143 FROM ttrss_counters_cache, ttrss_feeds
144 WHERE id = feed_id AND
145 (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND
146 ttrss_counters_cache.owner_uid = :uid AND
147 ttrss_feeds.owner_uid = :uid");
148 $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
149 $row = $sth->fetch();
151 $unread = (int) $row["sv"];
154 $unread = (int) Feeds
::getFeedArticles($feed_id, $is_cat, true, $owner_uid);
157 $tr_in_progress = false;
160 $pdo->beginTransaction();
161 } catch (Exception
$e) {
162 $tr_in_progress = true;
165 $sth = $pdo->prepare("SELECT feed_id FROM $table
166 WHERE owner_uid = ? AND feed_id = ? LIMIT 1");
167 $sth->execute([$owner_uid, $feed_id]);
171 $sth = $pdo->prepare("UPDATE $table SET
172 value = ?, updated = NOW() WHERE
173 feed_id = ? AND owner_uid = ?");
175 $sth->execute([$unread, $feed_id, $owner_uid]);
178 $sth = $pdo->prepare("INSERT INTO $table
179 (feed_id, value, owner_uid, updated)
182 $sth->execute([$feed_id, $unread, $owner_uid]);
185 if (!$tr_in_progress) $pdo->commit();
187 if ($feed_id > 0 && $prev_unread != $unread) {
191 /* Update parent category */
195 $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds
196 WHERE owner_uid = ? AND id = ?");
197 $sth->execute([$owner_uid, $feed_id]);
199 if ($row = $sth->fetch()) {
200 CCache
::update((int)$row["cat_id"], $owner_uid, true, true, true);
204 } else if ($feed_id < 0) {
205 CCache
::update_all($owner_uid);