move counter cache to a separate class
fix references to get_article_tags
This commit is contained in:
parent
aeb1abedb2
commit
2ed0d6c433
|
@ -297,7 +297,7 @@ class API extends Handler {
|
||||||
WHERE ref_id IN ($article_ids)");
|
WHERE ref_id IN ($article_ids)");
|
||||||
|
|
||||||
while ($line = $this->dbh->fetch_assoc($result)) {
|
while ($line = $this->dbh->fetch_assoc($result)) {
|
||||||
ccache_update($line["feed_id"], $_SESSION["uid"]);
|
CCache::update($line["feed_id"], $_SESSION["uid"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ class Article extends Handler_Protected {
|
||||||
}
|
}
|
||||||
|
|
||||||
$feed_id = $this->getArticleFeed($id);
|
$feed_id = $this->getArticleFeed($id);
|
||||||
ccache_update($feed_id, $_SESSION["uid"]);
|
CCache::update($feed_id, $_SESSION["uid"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function create_published_article($title, $url, $content, $labels_str,
|
static function create_published_article($title, $url, $content, $labels_str,
|
||||||
|
@ -544,7 +544,7 @@ class Article extends Handler_Protected {
|
||||||
SET unread = false,last_read = NOW()
|
SET unread = false,last_read = NOW()
|
||||||
WHERE ref_id = '$id' AND owner_uid = $owner_uid");
|
WHERE ref_id = '$id' AND owner_uid = $owner_uid");
|
||||||
|
|
||||||
ccache_update($feed_id, $owner_uid);
|
CCache::update($feed_id, $owner_uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = db_query("SELECT id,title,link,content,feed_id,comments,int_id,lang,
|
$result = db_query("SELECT id,title,link,content,feed_id,comments,int_id,lang,
|
||||||
|
@ -909,7 +909,7 @@ class Article extends Handler_Protected {
|
||||||
WHERE ($ids_qpart) AND owner_uid = $owner_uid");
|
WHERE ($ids_qpart) AND owner_uid = $owner_uid");
|
||||||
|
|
||||||
while ($line = db_fetch_assoc($result)) {
|
while ($line = db_fetch_assoc($result)) {
|
||||||
ccache_update($line["feed_id"], $owner_uid);
|
CCache::update($line["feed_id"], $owner_uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
class CCache {
|
||||||
/* function ccache_zero($feed_id, $owner_uid) {
|
/* function ccache_zero($feed_id, $owner_uid) {
|
||||||
db_query("UPDATE ttrss_counters_cache SET
|
db_query("UPDATE ttrss_counters_cache SET
|
||||||
value = 0, updated = NOW() WHERE
|
value = 0, updated = NOW() WHERE
|
||||||
feed_id = '$feed_id' AND owner_uid = '$owner_uid'");
|
feed_id = '$feed_id' AND owner_uid = '$owner_uid'");
|
||||||
} */
|
} */
|
||||||
|
|
||||||
function ccache_zero_all($owner_uid) {
|
static function zero_all($owner_uid) {
|
||||||
db_query("UPDATE ttrss_counters_cache SET
|
db_query("UPDATE ttrss_counters_cache SET
|
||||||
value = 0 WHERE owner_uid = '$owner_uid'");
|
value = 0 WHERE owner_uid = '$owner_uid'");
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
value = 0 WHERE owner_uid = '$owner_uid'");
|
value = 0 WHERE owner_uid = '$owner_uid'");
|
||||||
}
|
}
|
||||||
|
|
||||||
function ccache_remove($feed_id, $owner_uid, $is_cat = false) {
|
static function remove($feed_id, $owner_uid, $is_cat = false) {
|
||||||
|
|
||||||
if (!$is_cat) {
|
if (!$is_cat) {
|
||||||
$table = "ttrss_counters_cache";
|
$table = "ttrss_counters_cache";
|
||||||
|
@ -26,7 +27,7 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ccache_update_all($owner_uid) {
|
static function update_all($owner_uid) {
|
||||||
|
|
||||||
if (get_pref('ENABLE_FEED_CATS', $owner_uid)) {
|
if (get_pref('ENABLE_FEED_CATS', $owner_uid)) {
|
||||||
|
|
||||||
|
@ -34,26 +35,26 @@
|
||||||
WHERE feed_id > 0 AND owner_uid = '$owner_uid'");
|
WHERE feed_id > 0 AND owner_uid = '$owner_uid'");
|
||||||
|
|
||||||
while ($line = db_fetch_assoc($result)) {
|
while ($line = db_fetch_assoc($result)) {
|
||||||
ccache_update($line["feed_id"], $owner_uid, true);
|
CCache::update($line["feed_id"], $owner_uid, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We have to manually include category 0 */
|
/* We have to manually include category 0 */
|
||||||
|
|
||||||
ccache_update(0, $owner_uid, true);
|
CCache::update(0, $owner_uid, true);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$result = db_query("SELECT feed_id FROM ttrss_counters_cache
|
$result = db_query("SELECT feed_id FROM ttrss_counters_cache
|
||||||
WHERE feed_id > 0 AND owner_uid = '$owner_uid'");
|
WHERE feed_id > 0 AND owner_uid = '$owner_uid'");
|
||||||
|
|
||||||
while ($line = db_fetch_assoc($result)) {
|
while ($line = db_fetch_assoc($result)) {
|
||||||
print ccache_update($line["feed_id"], $owner_uid);
|
print CCache::update($line["feed_id"], $owner_uid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ccache_find($feed_id, $owner_uid, $is_cat = false,
|
static function find($feed_id, $owner_uid, $is_cat = false,
|
||||||
$no_update = false) {
|
$no_update = false) {
|
||||||
|
|
||||||
if (!is_numeric($feed_id)) return;
|
if (!is_numeric($feed_id)) return;
|
||||||
|
@ -85,13 +86,13 @@
|
||||||
if ($no_update) {
|
if ($no_update) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return ccache_update($feed_id, $owner_uid, $is_cat);
|
return CCache::update($feed_id, $owner_uid, $is_cat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ccache_update($feed_id, $owner_uid, $is_cat = false,
|
static function update($feed_id, $owner_uid, $is_cat = false,
|
||||||
$update_pcat = true, $pcat_fast = false) {
|
$update_pcat = true, $pcat_fast = false) {
|
||||||
|
|
||||||
if (!is_numeric($feed_id)) return;
|
if (!is_numeric($feed_id)) return;
|
||||||
|
@ -102,13 +103,13 @@
|
||||||
$owner_uid = db_fetch_result($tmp_result, 0, "owner_uid");
|
$owner_uid = db_fetch_result($tmp_result, 0, "owner_uid");
|
||||||
} */
|
} */
|
||||||
|
|
||||||
$prev_unread = ccache_find($feed_id, $owner_uid, $is_cat, true);
|
$prev_unread = CCache::find($feed_id, $owner_uid, $is_cat, true);
|
||||||
|
|
||||||
/* When updating a label, all we need to do is recalculate feed counters
|
/* When updating a label, all we need to do is recalculate feed counters
|
||||||
* because labels are not cached */
|
* because labels are not cached */
|
||||||
|
|
||||||
if ($feed_id < 0) {
|
if ($feed_id < 0) {
|
||||||
ccache_update_all($owner_uid);
|
CCache::update_all($owner_uid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@
|
||||||
WHERE owner_uid = '$owner_uid' AND $cat_qpart");
|
WHERE owner_uid = '$owner_uid' AND $cat_qpart");
|
||||||
|
|
||||||
while ($line = db_fetch_assoc($result)) {
|
while ($line = db_fetch_assoc($result)) {
|
||||||
ccache_update($line["id"], $owner_uid, false, false);
|
CCache::update($line["id"], $owner_uid, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,12 +181,12 @@
|
||||||
|
|
||||||
$cat_id = (int) db_fetch_result($result, 0, "cat_id");
|
$cat_id = (int) db_fetch_result($result, 0, "cat_id");
|
||||||
|
|
||||||
ccache_update($cat_id, $owner_uid, true, true, true);
|
CCache::update($cat_id, $owner_uid, true, true, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ($feed_id < 0) {
|
} else if ($feed_id < 0) {
|
||||||
ccache_update_all($owner_uid);
|
CCache::update_all($owner_uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $unread;
|
return $unread;
|
||||||
|
@ -223,3 +224,5 @@
|
||||||
}
|
}
|
||||||
} */
|
} */
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -836,7 +836,7 @@ class Feeds extends Handler_Protected {
|
||||||
function catchupAll() {
|
function catchupAll() {
|
||||||
$this->dbh->query("UPDATE ttrss_user_entries SET
|
$this->dbh->query("UPDATE ttrss_user_entries SET
|
||||||
last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
|
last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
|
||||||
ccache_zero_all($_SESSION["uid"]);
|
CCache::zero_all($_SESSION["uid"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function view() {
|
function view() {
|
||||||
|
@ -890,7 +890,7 @@ class Feeds extends Handler_Protected {
|
||||||
* so for performance reasons we don't do that here */
|
* so for performance reasons we don't do that here */
|
||||||
|
|
||||||
if ($feed >= 0) {
|
if ($feed >= 0) {
|
||||||
ccache_update($feed, $_SESSION["uid"], $cat_view);
|
CCache::update($feed, $_SESSION["uid"], $cat_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_pref("_DEFAULT_VIEW_MODE", $view_mode);
|
set_pref("_DEFAULT_VIEW_MODE", $view_mode);
|
||||||
|
@ -1365,7 +1365,7 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ccache_update($feed, $owner_uid, $cat_view);
|
CCache::update($feed, $owner_uid, $cat_view);
|
||||||
|
|
||||||
} else { // tag
|
} else { // tag
|
||||||
db_query("UPDATE ttrss_user_entries
|
db_query("UPDATE ttrss_user_entries
|
||||||
|
|
|
@ -227,7 +227,7 @@ class Handler_Public extends Handler {
|
||||||
if ($line['note']) $article['note'] = $line['note'];
|
if ($line['note']) $article['note'] = $line['note'];
|
||||||
if ($article['author']) $article['author'] = $line['author'];
|
if ($article['author']) $article['author'] = $line['author'];
|
||||||
|
|
||||||
$tags = get_article_tags($line["id"], $owner_uid);
|
$tags = Article::get_article_tags($line["id"], $owner_uid);
|
||||||
|
|
||||||
if (count($tags) > 0) {
|
if (count($tags) > 0) {
|
||||||
$article['tags'] = array();
|
$article['tags'] = array();
|
||||||
|
|
|
@ -1168,7 +1168,7 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
|
|
||||||
while ($line = $this->dbh->fetch_assoc($result)) {
|
while ($line = $this->dbh->fetch_assoc($result)) {
|
||||||
|
|
||||||
$tags = get_article_tags($line["ref_id"]);
|
$tags = Article::get_article_tags($line["ref_id"]);
|
||||||
|
|
||||||
$article_filters = get_article_filters($filters, $line['title'],
|
$article_filters = get_article_filters($filters, $line['title'],
|
||||||
$line['content'], $line['link'], strtotime($line['updated']),
|
$line['content'], $line['link'], strtotime($line['updated']),
|
||||||
|
@ -1225,7 +1225,7 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
|
|
||||||
while ($line = $this->dbh->fetch_assoc($tmp_result)) {
|
while ($line = $this->dbh->fetch_assoc($tmp_result)) {
|
||||||
|
|
||||||
$tags = get_article_tags($line["ref_id"]);
|
$tags = Article::get_article_tags($line["ref_id"]);
|
||||||
|
|
||||||
$article_filters = get_article_filters($filters, $line['title'],
|
$article_filters = get_article_filters($filters, $line['title'],
|
||||||
$line['content'], $line['link'], strtotime($line['updated']),
|
$line['content'], $line['link'], strtotime($line['updated']),
|
||||||
|
@ -1535,7 +1535,7 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
$cat_id = (int) $cat_id;
|
$cat_id = (int) $cat_id;
|
||||||
|
|
||||||
if ($cat_id > 0) {
|
if ($cat_id > 0) {
|
||||||
$cat_unread = ccache_find($cat_id, $_SESSION["uid"], true);
|
$cat_unread = CCache::find($cat_id, $_SESSION["uid"], true);
|
||||||
} else if ($cat_id == 0 || $cat_id == -2) {
|
} else if ($cat_id == 0 || $cat_id == -2) {
|
||||||
$cat_unread = Feeds::getCategoryUnread($cat_id);
|
$cat_unread = Feeds::getCategoryUnread($cat_id);
|
||||||
}
|
}
|
||||||
|
@ -1740,7 +1740,7 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
$result = $this->dbh->query("DELETE FROM ttrss_entries WHERE
|
$result = $this->dbh->query("DELETE FROM ttrss_entries WHERE
|
||||||
(SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
|
(SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
|
||||||
|
|
||||||
ccache_update($id, $_SESSION['uid']);
|
CCache::update($id, $_SESSION['uid']);
|
||||||
} // function clear_feed_articles
|
} // function clear_feed_articles
|
||||||
|
|
||||||
private function remove_feed_category($id, $owner_uid) {
|
private function remove_feed_category($id, $owner_uid) {
|
||||||
|
@ -1748,7 +1748,7 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
$this->dbh->query("DELETE FROM ttrss_feed_categories
|
$this->dbh->query("DELETE FROM ttrss_feed_categories
|
||||||
WHERE id = '$id' AND owner_uid = $owner_uid");
|
WHERE id = '$id' AND owner_uid = $owner_uid");
|
||||||
|
|
||||||
ccache_remove($id, $owner_uid, true);
|
CCache::remove($id, $owner_uid, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function remove_feed($id, $owner_uid) {
|
static function remove_feed($id, $owner_uid) {
|
||||||
|
@ -1803,11 +1803,11 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
unlink(ICONS_DIR . "/$id.ico");
|
unlink(ICONS_DIR . "/$id.ico");
|
||||||
}
|
}
|
||||||
|
|
||||||
ccache_remove($id, $owner_uid);
|
CCache::remove($id, $owner_uid);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
label_remove(feed_to_label_id($id), $owner_uid);
|
label_remove(feed_to_label_id($id), $owner_uid);
|
||||||
//ccache_remove($id, $owner_uid); don't think labels are cached
|
//CCache::remove($id, $owner_uid); don't think labels are cached
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,6 @@
|
||||||
|
|
||||||
require_once 'db-prefs.php';
|
require_once 'db-prefs.php';
|
||||||
require_once 'version.php';
|
require_once 'version.php';
|
||||||
require_once 'ccache.php';
|
|
||||||
require_once 'labels.php';
|
require_once 'labels.php';
|
||||||
require_once 'controls.php';
|
require_once 'controls.php';
|
||||||
|
|
||||||
|
@ -233,7 +232,7 @@
|
||||||
|
|
||||||
if ($purge_interval == -1 || !$purge_interval) {
|
if ($purge_interval == -1 || !$purge_interval) {
|
||||||
if ($owner_uid) {
|
if ($owner_uid) {
|
||||||
ccache_update($feed_id, $owner_uid);
|
CCache::update($feed_id, $owner_uid);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -277,7 +276,7 @@
|
||||||
|
|
||||||
$rows = db_affected_rows($result);
|
$rows = db_affected_rows($result);
|
||||||
|
|
||||||
ccache_update($feed_id, $owner_uid);
|
CCache::update($feed_id, $owner_uid);
|
||||||
|
|
||||||
if ($debug) {
|
if ($debug) {
|
||||||
_debug("Purged feed $feed_id ($purge_interval): deleted $rows articles");
|
_debug("Purged feed $feed_id ($purge_interval): deleted $rows articles");
|
||||||
|
@ -1078,7 +1077,7 @@
|
||||||
/* Special case: NULL category doesn't actually exist in the DB */
|
/* Special case: NULL category doesn't actually exist in the DB */
|
||||||
|
|
||||||
$cv = array("id" => 0, "kind" => "cat",
|
$cv = array("id" => 0, "kind" => "cat",
|
||||||
"counter" => (int) ccache_find(0, $_SESSION["uid"], true));
|
"counter" => (int) CCache::find(0, $_SESSION["uid"], true));
|
||||||
|
|
||||||
array_push($ret_arr, $cv);
|
array_push($ret_arr, $cv);
|
||||||
|
|
||||||
|
|
|
@ -686,7 +686,7 @@
|
||||||
$article_labels = get_article_labels($base_entry_id, $owner_uid);
|
$article_labels = get_article_labels($base_entry_id, $owner_uid);
|
||||||
$entry_language = db_fetch_result($result, 0, "lang");
|
$entry_language = db_fetch_result($result, 0, "lang");
|
||||||
|
|
||||||
$existing_tags = get_article_tags($base_entry_id, $owner_uid);
|
$existing_tags = Article::get_article_tags($base_entry_id, $owner_uid);
|
||||||
$entry_tags = array_unique(array_merge($entry_tags, $existing_tags));
|
$entry_tags = array_unique(array_merge($entry_tags, $existing_tags));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue