]> git.wh0rd.org Git - tt-rss.git/commitdiff
add tag cache for user_entries (bump schema)
authorAndrew Dolgov <fox@fakecake.org>
Tue, 9 Nov 2010 19:41:13 +0000 (22:41 +0300)
committerAndrew Dolgov <fox@fakecake.org>
Tue, 9 Nov 2010 19:41:13 +0000 (22:41 +0300)
functions.php
modules/backend-rpc.php
sanity_check.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/72.sql [new file with mode: 0644]
schema/versions/pgsql/72.sql [new file with mode: 0644]

index 5e7b7c20f513ab343d4597bc75bc89fcb92237dd..c4d033bc20a653cdb3a0ef198a06b4ee77a447cf 100644 (file)
                                                $result = db_query($link,
                                                        "INSERT INTO ttrss_user_entries 
                                                                (ref_id, owner_uid, feed_id, unread, last_read, marked, 
-                                                                       published, score) 
+                                                                       published, score, tag_cache
                                                        VALUES ('$ref_id', '$owner_uid', '$feed', $unread,
-                                                               $last_read_qpart, $marked, $published, '$score')");
+                                                               $last_read_qpart, $marked, $published, '$score', '')");
 
                                                $result = db_query($link, 
                                                        "SELECT int_id FROM ttrss_user_entries WHERE
                                                                        (owner_uid,tag_name,post_int_id)
                                                                        VALUES ('$owner_uid','$tag', '$entry_int_id')");
                                                        }                                                       
+
+                                                       /* update the cache */
+
+                                                       $tags_str = db_escape_string(join(",", $filtered_tags));
+
+                                                       db_query($link, "UPDATE ttrss_user_entries 
+                                                               SET tag_cache = '$tags_str' WHERE ref_id = '$entry_ref_id'
+                                                               AND owner_uid = $owner_uid");
                                                }
 
                                        db_query($link, "COMMIT");
                if ($memcache && $obj = $memcache->get($obj_id)) {
                        $tags = $obj;
                } else {
-                       $tmp_result = db_query($link, $query);
+                       /* check cache first */
+
+                       $result = db_query($link, "SELECT tag_cache FROM ttrss_user_entries
+                               WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
+
+                       $tag_cache = db_fetch_result($result, 0, "tag_cache");
+
+                       if ($tag_cache) {
+                               $tags = explode(",", $tag_cache);
+                       } else {
 
-                       while ($tmp_line = db_fetch_assoc($tmp_result)) {
-                               array_push($tags, $tmp_line["tag_name"]);                               
+                               /* do it the hard way */
+
+                               $tmp_result = db_query($link, $query);
+
+                               while ($tmp_line = db_fetch_assoc($tmp_result)) {
+                                       array_push($tags, $tmp_line["tag_name"]);                               
+                               }
+
+                               /* update the cache */
+
+                               $tags_str = db_escape_string(join(",", $tags));
+
+                               db_query($link, "UPDATE ttrss_user_entries 
+                                       SET tag_cache = '$tags_str' WHERE ref_id = '$id'
+                                       AND owner_uid = " . $_SESSION["uid"]);
                        }
 
                        if ($memcache) $memcache->add($obj_id, $tags, 0, 3600);
index 8f31cd74861e703c9706b94b8f35b76006c22ff9..a825242c64363c7e519a09a4d63a46cfc7d47568 100644 (file)
                        $id = db_escape_string($_REQUEST["id"]);
 
                        $tags_str = db_escape_string($_REQUEST["tags_str"]);
-
                        $tags = array_unique(trim_array(split(",", $tags_str)));
+                       $tags_str = db_escape_string(join(",", $tags));
 
                        db_query($link, "BEGIN");
 
                                }
                        }
 
+                       db_query($link, "UPDATE ttrss_user_entries 
+                               SET tag_cache = '$tags_str' WHERE ref_id = '$id'
+                               AND owner_uid = " . $_SESSION["uid"]);
+
                        db_query($link, "COMMIT");
 
                        if ($memcache) {
index b5432199ef95d11dcf09e6e8b34db39976e8d7c6..20ef276c0dff5e83eca2aa4a3bd0e7b725c0f525 100644 (file)
@@ -2,7 +2,7 @@
        require_once "functions.php";
 
        define('EXPECTED_CONFIG_VERSION', 19);
-       define('SCHEMA_VERSION', 71);
+       define('SCHEMA_VERSION', 72);
 
        if (!file_exists("config.php")) {
                print "<b>Fatal Error</b>: You forgot to copy 
index da73cedd4b95b78bbfda3d2307bde71e2b51c12e..527957038c9d2c9c0b01a9b34a55ddd2c5261002 100644 (file)
@@ -151,6 +151,7 @@ create table ttrss_user_entries (
        owner_uid integer not null,
        marked bool not null default 0,
        published bool not null default 0,
+       tag_cache text not null,
        last_read datetime,
        score int not null default 0,
        note longtext,
@@ -244,7 +245,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;
 
-insert into ttrss_version values (71);
+insert into ttrss_version values (72);
 
 create table ttrss_enclosures (id integer primary key auto_increment,
        content_url text not null,
index 3583639c6ce50dc9b4c69758ffd7883dc86cd7d5..29c82c0d29a885df346c6e553615fb688f43c957 100644 (file)
@@ -137,6 +137,7 @@ create table ttrss_user_entries (
        owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
        marked boolean not null default false,
        published boolean not null default false,
+       tag_cache text not null,
        last_read timestamp,
        score int not null default 0,
        note text,
@@ -216,7 +217,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (71);
+insert into ttrss_version values (72);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
diff --git a/schema/versions/mysql/72.sql b/schema/versions/mysql/72.sql
new file mode 100644 (file)
index 0000000..c9b74ba
--- /dev/null
@@ -0,0 +1,5 @@
+alter table ttrss_user_entries add column tag_cache text;
+update ttrss_user_entries set tag_cache = '';
+alter table ttrss_user_entries change tag_cache tag_cache text not null;
+
+update ttrss_version set schema_version = 72;
diff --git a/schema/versions/pgsql/72.sql b/schema/versions/pgsql/72.sql
new file mode 100644 (file)
index 0000000..7b260b3
--- /dev/null
@@ -0,0 +1,5 @@
+alter table ttrss_user_entries add column tag_cache text;
+update ttrss_user_entries set tag_cache = '';
+alter table ttrss_user_entries alter column tag_cache set not null;
+
+update ttrss_version set schema_version = 72;