implement label cache; misc fixes (bump schema)

This commit is contained in:
Andrew Dolgov 2010-11-10 18:50:51 +03:00
parent 23d064cc81
commit 905ff52a36
8 changed files with 109 additions and 39 deletions

View file

@ -334,6 +334,8 @@
break; break;
} }
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
$ret = outputHeadlinesList($link, $feed, $subop, $ret = outputHeadlinesList($link, $feed, $subop,
$view_mode, $limit, $cat_view, $next_unread_feed, $offset, $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
$vgroup_last_feed, $override_order); $vgroup_last_feed, $override_order);
@ -346,6 +348,8 @@
print "]]></headlines>"; print "]]></headlines>";
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
//print "<headlines-count value=\"$headlines_count\"/>"; //print "<headlines-count value=\"$headlines_count\"/>";
//print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>"; //print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";

View file

@ -1181,9 +1181,9 @@
$result = db_query($link, $result = db_query($link,
"INSERT INTO ttrss_user_entries "INSERT INTO ttrss_user_entries
(ref_id, owner_uid, feed_id, unread, last_read, marked, (ref_id, owner_uid, feed_id, unread, last_read, marked,
published, score, tag_cache) published, score, tag_cache, label_cache)
VALUES ('$ref_id', '$owner_uid', '$feed', $unread, VALUES ('$ref_id', '$owner_uid', '$feed', $unread,
$last_read_qpart, $marked, $published, '$score', '')"); $last_read_qpart, $marked, $published, '$score', '', '')");
$result = db_query($link, $result = db_query($link,
"SELECT int_id FROM ttrss_user_entries WHERE "SELECT int_id FROM ttrss_user_entries WHERE
@ -5080,7 +5080,7 @@
$labels_str .= format_article_labels($labels, $id); $labels_str .= format_article_labels($labels, $id);
$labels_str .= "</span>"; $labels_str .= "</span>";
if (count($topmost_article_ids) < 5) { if (count($topmost_article_ids) < 3) {
array_push($topmost_article_ids, $id); array_push($topmost_article_ids, $id);
} }
@ -6089,6 +6089,30 @@
function get_article_labels($link, $id) { function get_article_labels($link, $id) {
global $memcache; global $memcache;
$obj_id = md5("LABELS:$id:" . $_SESSION["uid"]);
$rv = array();
if ($memcache && $obj = $memcache->get($obj_id)) {
return $obj;
} else {
$result = db_query($link, "SELECT label_cache FROM
ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " .
$_SESSION["uid"]);
$label_cache = db_fetch_result($result, 0, "label_cache");
if ($label_cache) {
$label_cache = json_decode($label_cache, true);
if ($label_cache["no-labels"] == 1)
return $rv;
else
return $label_cache;
}
$result = db_query($link, $result = db_query($link,
"SELECT DISTINCT label_id,caption,fg_color,bg_color "SELECT DISTINCT label_id,caption,fg_color,bg_color
FROM ttrss_labels2, ttrss_user_labels2 FROM ttrss_labels2, ttrss_user_labels2
@ -6097,19 +6121,17 @@
AND owner_uid = ".$_SESSION["uid"] . " AND owner_uid = ".$_SESSION["uid"] . "
ORDER BY caption"); ORDER BY caption");
$obj_id = md5("LABELS:$id:" . $_SESSION["uid"]);
$rv = array();
if ($memcache && $obj = $memcache->get($obj_id)) {
return $obj;
} else {
while ($line = db_fetch_assoc($result)) { while ($line = db_fetch_assoc($result)) {
$rk = array($line["label_id"], $line["caption"], $line["fg_color"], $rk = array($line["label_id"], $line["caption"], $line["fg_color"],
$line["bg_color"]); $line["bg_color"]);
array_push($rv, $rk); array_push($rv, $rk);
} }
if ($memcache) $memcache->add($obj_id, $rv, 0, 3600); if ($memcache) $memcache->add($obj_id, $rv, 0, 3600);
if (count($rv) > 0)
label_update_cache($link, $id, $rv);
else
label_update_cache($link, $id, array("no-labels" => 1));
} }
return $rv; return $rv;
@ -6128,6 +6150,28 @@
} }
} }
function label_update_cache($link, $id, $labels = false, $force = false) {
if ($force)
label_clear_cache($link, $id);
if (!$labels)
$labels = get_article_labels($link, $id);
$labels = db_escape_string(json_encode($labels));
db_query($link, "UPDATE ttrss_user_entries SET
label_cache = '$labels' WHERE ref_id = '$id'");
}
function label_clear_cache($link, $id) {
db_query($link, "UPDATE ttrss_user_entries SET
label_cache = '' WHERE ref_id = '$id'");
}
function label_remove_article($link, $id, $label, $owner_uid) { function label_remove_article($link, $id, $label, $owner_uid) {
$label_id = label_find_id($link, $label, $owner_uid); $label_id = label_find_id($link, $label, $owner_uid);
@ -6139,6 +6183,8 @@
WHERE WHERE
label_id = '$label_id' AND label_id = '$label_id' AND
article_id = '$id'"); article_id = '$id'");
label_clear_cache($link, $id);
} }
function label_add_article($link, $id, $label, $owner_uid) { function label_add_article($link, $id, $label, $owner_uid) {
@ -6167,11 +6213,16 @@
db_query($link, "INSERT INTO ttrss_user_labels2 db_query($link, "INSERT INTO ttrss_user_labels2
(label_id, article_id) VALUES ('$label_id', '$id')"); (label_id, article_id) VALUES ('$label_id', '$id')");
} }
label_clear_cache($link, $id);
} }
function label_remove($link, $id, $owner_uid) { function label_remove($link, $id, $owner_uid) {
global $memcache; global $memcache;
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
if ($memcache) { if ($memcache) {
$obj_id = md5("LABELS:$id:$owner_uid"); $obj_id = md5("LABELS:$id:$owner_uid");
$memcache->delete($obj_id); $memcache->delete($obj_id);
@ -6185,7 +6236,7 @@
$caption = db_fetch_result($result, 0, "caption"); $caption = db_fetch_result($result, 0, "caption");
$result = db_query($link, "DELETE FROM ttrss_labels2 WHERE id = '$id' $result = db_query($link, "DELETE FROM ttrss_labels2 WHERE id = '$id'
AND owner_uid = " . $_SESSION["uid"]); AND owner_uid = " . $owner_uid);
if (db_affected_rows($link, $result) != 0 && $caption) { if (db_affected_rows($link, $result) != 0 && $caption) {
@ -6201,7 +6252,13 @@
db_query($link, "UPDATE ttrss_filters SET db_query($link, "UPDATE ttrss_filters SET
enabled = false WHERE action_param = '$caption' enabled = false WHERE action_param = '$caption'
AND action_id = 7 AND action_id = 7
AND owner_uid = " . $_SESSION["uid"]); AND owner_uid = " . $owner_uid);
/* Remove cached data */
db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $owner_uid);
} }
db_query($link, "COMMIT"); db_query($link, "COMMIT");
@ -6938,7 +6995,7 @@
} }
} }
if (db_num_rows($result) == 1) { if (count($entries) == 1) {
print __("Attachment:") . " "; print __("Attachment:") . " ";
} else { } else {
print __("Attachments:") . " "; print __("Attachments:") . " ";

View file

@ -595,7 +595,7 @@
if ($subop == "removeFromLabel") { if ($subop == "removeFromLabel") {
$ids = split(",", db_escape_string($_REQUEST["ids"])); $ids = explode(",", db_escape_string($_REQUEST["ids"]));
$label_id = db_escape_string($_REQUEST["lid"]); $label_id = db_escape_string($_REQUEST["lid"]);
$label = db_escape_string(label_find_caption($link, $label_id, $label = db_escape_string(label_find_caption($link, $label_id,

View file

@ -21,6 +21,14 @@
fg_color = '$fg', bg_color = '$bg' WHERE id = '$id' fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
AND owner_uid = " . $_SESSION["uid"]); AND owner_uid = " . $_SESSION["uid"]);
} }
$caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
/* Remove cached data */
db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
} }
return; return;
@ -33,6 +41,13 @@
db_query($link, "UPDATE ttrss_labels2 SET db_query($link, "UPDATE ttrss_labels2 SET
fg_color = '', bg_color = '' WHERE id = '$id' fg_color = '', bg_color = '' WHERE id = '$id'
AND owner_uid = " . $_SESSION["uid"]); AND owner_uid = " . $_SESSION["uid"]);
$caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
/* Remove cached data */
db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
} }
} }

View file

@ -2,7 +2,7 @@
require_once "functions.php"; require_once "functions.php";
define('EXPECTED_CONFIG_VERSION', 19); define('EXPECTED_CONFIG_VERSION', 19);
define('SCHEMA_VERSION', 73); define('SCHEMA_VERSION', 74);
if (!file_exists("config.php")) { if (!file_exists("config.php")) {
print "<b>Fatal Error</b>: You forgot to copy print "<b>Fatal Error</b>: You forgot to copy

View file

@ -152,6 +152,7 @@ create table ttrss_user_entries (
marked bool not null default 0, marked bool not null default 0,
published bool not null default 0, published bool not null default 0,
tag_cache text not null, tag_cache text not null,
label_cache text not null,
last_read datetime, last_read datetime,
score int not null default 0, score int not null default 0,
note longtext, note longtext,
@ -245,7 +246,7 @@ create table ttrss_tags (id integer primary key auto_increment,
create table ttrss_version (schema_version int not null) TYPE=InnoDB DEFAULT CHARSET=UTF8; create table ttrss_version (schema_version int not null) TYPE=InnoDB DEFAULT CHARSET=UTF8;
insert into ttrss_version values (73); insert into ttrss_version values (74);
create table ttrss_enclosures (id integer primary key auto_increment, create table ttrss_enclosures (id integer primary key auto_increment,
content_url text not null, content_url text not null,

View file

@ -138,6 +138,7 @@ create table ttrss_user_entries (
marked boolean not null default false, marked boolean not null default false,
published boolean not null default false, published boolean not null default false,
tag_cache text not null, tag_cache text not null,
label_cache text not null,
last_read timestamp, last_read timestamp,
score int not null default 0, score int not null default 0,
note text, note text,
@ -217,7 +218,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid);
create table ttrss_version (schema_version int not null); create table ttrss_version (schema_version int not null);
insert into ttrss_version values (73); insert into ttrss_version values (74);
create table ttrss_enclosures (id serial not null primary key, create table ttrss_enclosures (id serial not null primary key,
content_url text not null, content_url text not null,

View file

@ -934,6 +934,8 @@ function selectionRemoveLabel(id) {
var query = "?op=rpc&subop=removeFromLabel&ids=" + var query = "?op=rpc&subop=removeFromLabel&ids=" +
param_escape(ids.toString()) + "&lid=" + param_escape(id); param_escape(ids.toString()) + "&lid=" + param_escape(id);
console.log(query);
// notify_progress("Loading, please wait..."); // notify_progress("Loading, please wait...");
cache_invalidate("F:" + (-11 - id)); cache_invalidate("F:" + (-11 - id));
@ -972,6 +974,8 @@ function selectionAssignLabel(id) {
var query = "?op=rpc&subop=assignToLabel&ids=" + var query = "?op=rpc&subop=assignToLabel&ids=" +
param_escape(ids.toString()) + "&lid=" + param_escape(id); param_escape(ids.toString()) + "&lid=" + param_escape(id);
console.log(query);
// notify_progress("Loading, please wait..."); // notify_progress("Loading, please wait...");
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
@ -1831,20 +1835,13 @@ function cache_expire() {
var date = new Date(); var date = new Date();
var timestamp = Math.round(date.getTime() / 1000); var timestamp = Math.round(date.getTime() / 1000);
for (var id in cache_added) { for (var i = 0; i < localStorage.length; i++) {
var tmp = [];
var key_id = id.replace("TS:", ""); var id = localStorage.key(i);
//console.warn("CEXP:" + key_id); if (timestamp - cache_added["TS:" + id] > 180) {
localStorage.removeItem(id);
if (timestamp - cache_added[id] > 180) {
cache_invalidate(key_id);
} else {
tmp[id] = cache_added[id];
} }
cache_added = tmp;
} }
} else { } else {
@ -1875,25 +1872,20 @@ function cache_invalidate(id) {
if (has_local_storage()) { if (has_local_storage()) {
var tmp = [];
var found = false; var found = false;
for (var key in cache_added) { for (var i = 0; i < localStorage.length; i++) {
var key_id = key.replace("TS:", ""); var key = localStorage.key(i);
// console.warn("cache_invalidate: " + key_id + " cmp " + id); // console.warn("cache_invalidate: " + key_id + " cmp " + id);
if (key_id == id || key_id.indexOf(id + ":") == 0) { if (key == id || key.indexOf(id + ":") == 0) {
localStorage.removeItem(key_id); localStorage.removeItem(key);
found = true; found = true;
break; break;
} else {
tmp[key] = cache_added[key];
} }
} }
cache_added = tmp;
return found; return found;
} else { } else {