2013-01-22 19:32:17 +01:00
|
|
|
<?php
|
2013-04-17 16:34:18 +02:00
|
|
|
/* function ccache_zero($feed_id, $owner_uid) {
|
|
|
|
db_query("UPDATE ttrss_counters_cache SET
|
2013-01-22 19:32:17 +01:00
|
|
|
value = 0, updated = NOW() WHERE
|
|
|
|
feed_id = '$feed_id' AND owner_uid = '$owner_uid'");
|
|
|
|
} */
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
function ccache_zero_all($owner_uid) {
|
|
|
|
db_query("UPDATE ttrss_counters_cache SET
|
2013-01-22 19:32:17 +01:00
|
|
|
value = 0 WHERE owner_uid = '$owner_uid'");
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("UPDATE ttrss_cat_counters_cache SET
|
2013-01-22 19:32:17 +01:00
|
|
|
value = 0 WHERE owner_uid = '$owner_uid'");
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
function ccache_remove($feed_id, $owner_uid, $is_cat = false) {
|
2013-01-22 19:32:17 +01:00
|
|
|
|
|
|
|
if (!$is_cat) {
|
|
|
|
$table = "ttrss_counters_cache";
|
|
|
|
} else {
|
|
|
|
$table = "ttrss_cat_counters_cache";
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("DELETE FROM $table WHERE
|
2013-01-22 19:32:17 +01:00
|
|
|
feed_id = '$feed_id' AND owner_uid = '$owner_uid'");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
function ccache_update_all($owner_uid) {
|
2013-01-22 19:32:17 +01:00
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
if (get_pref('ENABLE_FEED_CATS', $owner_uid)) {
|
2013-01-22 19:32:17 +01:00
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$result = db_query("SELECT feed_id FROM ttrss_cat_counters_cache
|
2013-01-22 19:32:17 +01:00
|
|
|
WHERE feed_id > 0 AND owner_uid = '$owner_uid'");
|
|
|
|
|
|
|
|
while ($line = db_fetch_assoc($result)) {
|
2013-04-17 16:34:18 +02:00
|
|
|
ccache_update($line["feed_id"], $owner_uid, true);
|
2013-01-22 19:32:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We have to manually include category 0 */
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
ccache_update(0, $owner_uid, true);
|
2013-01-22 19:32:17 +01:00
|
|
|
|
|
|
|
} else {
|
2013-04-17 16:34:18 +02:00
|
|
|
$result = db_query("SELECT feed_id FROM ttrss_counters_cache
|
2013-01-22 19:32:17 +01:00
|
|
|
WHERE feed_id > 0 AND owner_uid = '$owner_uid'");
|
|
|
|
|
|
|
|
while ($line = db_fetch_assoc($result)) {
|
2013-04-17 16:34:18 +02:00
|
|
|
print ccache_update($line["feed_id"], $owner_uid);
|
2013-01-22 19:32:17 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
function ccache_find($feed_id, $owner_uid, $is_cat = false,
|
2013-01-22 19:32:17 +01:00
|
|
|
$no_update = false) {
|
|
|
|
|
|
|
|
if (!is_numeric($feed_id)) return;
|
|
|
|
|
|
|
|
if (!$is_cat) {
|
|
|
|
$table = "ttrss_counters_cache";
|
2013-02-27 12:16:00 +01:00
|
|
|
/* if ($feed_id > 0) {
|
2013-04-17 16:34:18 +02:00
|
|
|
$tmp_result = db_query("SELECT owner_uid FROM ttrss_feeds
|
2013-01-22 19:32:17 +01:00
|
|
|
WHERE id = '$feed_id'");
|
|
|
|
$owner_uid = db_fetch_result($tmp_result, 0, "owner_uid");
|
2013-02-27 12:16:00 +01:00
|
|
|
} */
|
2013-01-22 19:32:17 +01:00
|
|
|
} else {
|
|
|
|
$table = "ttrss_cat_counters_cache";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DB_TYPE == "pgsql") {
|
|
|
|
$date_qpart = "updated > NOW() - INTERVAL '15 minutes'";
|
|
|
|
} else if (DB_TYPE == "mysql") {
|
|
|
|
$date_qpart = "updated > DATE_SUB(NOW(), INTERVAL 15 MINUTE)";
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$result = db_query("SELECT value FROM $table
|
2013-01-22 19:32:17 +01:00
|
|
|
WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id'
|
|
|
|
LIMIT 1");
|
|
|
|
|
|
|
|
if (db_num_rows($result) == 1) {
|
|
|
|
return db_fetch_result($result, 0, "value");
|
|
|
|
} else {
|
|
|
|
if ($no_update) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
2013-04-17 16:34:18 +02:00
|
|
|
return ccache_update($feed_id, $owner_uid, $is_cat);
|
2013-01-22 19:32:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
function ccache_update($feed_id, $owner_uid, $is_cat = false,
|
2013-10-09 14:58:31 +02:00
|
|
|
$update_pcat = true, $pcat_fast = false) {
|
2013-01-22 19:32:17 +01:00
|
|
|
|
|
|
|
if (!is_numeric($feed_id)) return;
|
|
|
|
|
2013-02-27 12:16:00 +01:00
|
|
|
/* if (!$is_cat && $feed_id > 0) {
|
2013-04-17 16:34:18 +02:00
|
|
|
$tmp_result = db_query("SELECT owner_uid FROM ttrss_feeds
|
2013-01-22 19:32:17 +01:00
|
|
|
WHERE id = '$feed_id'");
|
|
|
|
$owner_uid = db_fetch_result($tmp_result, 0, "owner_uid");
|
2013-02-27 12:16:00 +01:00
|
|
|
} */
|
2013-01-22 19:32:17 +01:00
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$prev_unread = ccache_find($feed_id, $owner_uid, $is_cat, true);
|
2013-01-22 19:32:17 +01:00
|
|
|
|
|
|
|
/* When updating a label, all we need to do is recalculate feed counters
|
|
|
|
* because labels are not cached */
|
|
|
|
|
|
|
|
if ($feed_id < 0) {
|
2013-04-17 16:34:18 +02:00
|
|
|
ccache_update_all($owner_uid);
|
2013-01-22 19:32:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$is_cat) {
|
|
|
|
$table = "ttrss_counters_cache";
|
|
|
|
} else {
|
|
|
|
$table = "ttrss_cat_counters_cache";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($is_cat && $feed_id >= 0) {
|
|
|
|
if ($feed_id != 0) {
|
|
|
|
$cat_qpart = "cat_id = '$feed_id'";
|
|
|
|
} else {
|
|
|
|
$cat_qpart = "cat_id IS NULL";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recalculate counters for child feeds */
|
|
|
|
|
2013-10-09 14:58:31 +02:00
|
|
|
if (!$pcat_fast) {
|
|
|
|
$result = db_query("SELECT id FROM ttrss_feeds
|
2013-01-22 19:32:17 +01:00
|
|
|
WHERE owner_uid = '$owner_uid' AND $cat_qpart");
|
|
|
|
|
2013-10-09 14:58:31 +02:00
|
|
|
while ($line = db_fetch_assoc($result)) {
|
|
|
|
ccache_update($line["id"], $owner_uid, false, false);
|
|
|
|
}
|
2013-05-02 00:12:07 +02:00
|
|
|
}
|
2013-01-22 19:32:17 +01:00
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$result = db_query("SELECT SUM(value) AS sv
|
2013-01-22 19:32:17 +01:00
|
|
|
FROM ttrss_counters_cache, ttrss_feeds
|
|
|
|
WHERE id = feed_id AND $cat_qpart AND
|
2015-03-06 12:14:51 +01:00
|
|
|
ttrss_counters_cache.owner_uid = $owner_uid AND
|
2013-01-22 19:32:17 +01:00
|
|
|
ttrss_feeds.owner_uid = '$owner_uid'");
|
|
|
|
|
|
|
|
$unread = (int) db_fetch_result($result, 0, "sv");
|
|
|
|
|
|
|
|
} else {
|
move the following to Feeds:
+ static function catchup_feed($feed, $cat_view, $owner_uid = false, $mode = 'all', $search = false) {
+ static function getFeedArticles($feed, $is_cat = false, $unread_only = false,
+ static function subscribe_to_feed($url, $cat_id = 0,
+ static function getFeedIcon($id) {
+ static function getFeedTitle($id, $cat = false) {
+ static function getCategoryUnread($cat, $owner_uid = false) {
+ static function getCategoryChildrenUnread($cat, $owner_uid = false) {
2017-05-04 13:50:56 +02:00
|
|
|
$unread = (int) Feeds::getFeedArticles($feed_id, $is_cat, true, $owner_uid);
|
2013-01-22 19:32:17 +01:00
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("BEGIN");
|
2013-01-22 19:32:17 +01:00
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$result = db_query("SELECT feed_id FROM $table
|
2013-01-22 19:32:17 +01:00
|
|
|
WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id' LIMIT 1");
|
|
|
|
|
|
|
|
if (db_num_rows($result) == 1) {
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("UPDATE $table SET
|
2013-01-22 19:32:17 +01:00
|
|
|
value = '$unread', updated = NOW() WHERE
|
|
|
|
feed_id = '$feed_id' AND owner_uid = '$owner_uid'");
|
|
|
|
|
|
|
|
} else {
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("INSERT INTO $table
|
2013-01-22 19:32:17 +01:00
|
|
|
(feed_id, value, owner_uid, updated)
|
|
|
|
VALUES
|
|
|
|
($feed_id, $unread, $owner_uid, NOW())");
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("COMMIT");
|
2013-01-22 19:32:17 +01:00
|
|
|
|
|
|
|
if ($feed_id > 0 && $prev_unread != $unread) {
|
|
|
|
|
|
|
|
if (!$is_cat) {
|
|
|
|
|
|
|
|
/* Update parent category */
|
|
|
|
|
|
|
|
if ($update_pcat) {
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$result = db_query("SELECT cat_id FROM ttrss_feeds
|
2013-01-22 19:32:17 +01:00
|
|
|
WHERE owner_uid = '$owner_uid' AND id = '$feed_id'");
|
|
|
|
|
|
|
|
$cat_id = (int) db_fetch_result($result, 0, "cat_id");
|
|
|
|
|
2013-10-09 14:58:31 +02:00
|
|
|
ccache_update($cat_id, $owner_uid, true, true, true);
|
2013-01-22 19:32:17 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ($feed_id < 0) {
|
2013-04-17 16:34:18 +02:00
|
|
|
ccache_update_all($owner_uid);
|
2013-01-22 19:32:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $unread;
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
/* function ccache_cleanup($owner_uid) {
|
2013-01-22 19:32:17 +01:00
|
|
|
|
|
|
|
if (DB_TYPE == "pgsql") {
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("DELETE FROM ttrss_counters_cache AS c1 WHERE
|
2013-01-22 19:32:17 +01:00
|
|
|
(SELECT count(*) FROM ttrss_counters_cache AS c2
|
|
|
|
WHERE c1.feed_id = c2.feed_id AND c2.owner_uid = c1.owner_uid) > 1
|
|
|
|
AND owner_uid = '$owner_uid'");
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("DELETE FROM ttrss_cat_counters_cache AS c1 WHERE
|
2013-01-22 19:32:17 +01:00
|
|
|
(SELECT count(*) FROM ttrss_cat_counters_cache AS c2
|
|
|
|
WHERE c1.feed_id = c2.feed_id AND c2.owner_uid = c1.owner_uid) > 1
|
|
|
|
AND owner_uid = '$owner_uid'");
|
|
|
|
} else {
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("DELETE c1 FROM
|
2013-01-22 19:32:17 +01:00
|
|
|
ttrss_counters_cache AS c1,
|
|
|
|
ttrss_counters_cache AS c2
|
|
|
|
WHERE
|
|
|
|
c1.owner_uid = '$owner_uid' AND
|
|
|
|
c1.owner_uid = c2.owner_uid AND
|
|
|
|
c1.feed_id = c2.feed_id");
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("DELETE c1 FROM
|
2013-01-22 19:32:17 +01:00
|
|
|
ttrss_cat_counters_cache AS c1,
|
|
|
|
ttrss_cat_counters_cache AS c2
|
|
|
|
WHERE
|
|
|
|
c1.owner_uid = '$owner_uid' AND
|
|
|
|
c1.owner_uid = c2.owner_uid AND
|
|
|
|
c1.feed_id = c2.feed_id");
|
|
|
|
|
|
|
|
}
|
|
|
|
} */
|
2017-04-26 19:24:18 +02:00
|
|
|
|