]> git.wh0rd.org Git - tt-rss.git/commitdiff
offline: add trigger to remove label references when article is deleted
authorAndrew Dolgov <fox@bah.org.ru>
Sat, 7 Feb 2009 07:16:31 +0000 (10:16 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Sat, 7 Feb 2009 07:16:31 +0000 (10:16 +0300)
offline.js

index 172aea3143446757a0faf7f3900369fa3d6aa431..742bf739211fe28ad5f8a599207b3c8cd866b7d2 100644 (file)
@@ -1,4 +1,4 @@
-var SCHEMA_VERSION = 10;
+var SCHEMA_VERSION = 9;
 
 var offline_mode = false;
 var store = false;
@@ -671,7 +671,6 @@ function offline_download_parse(stage, transport) {
                                        if (a) {
 
                                                db.execute("DELETE FROM articles WHERE id = ?", [a.id]);
-                                               db.execute("DELETE FROM article_labels WHERE id = ?", [a.id]);
 
                                                db.execute("INSERT INTO articles "+
                                                "(id, feed_id, title, link, guid, updated, content, "+
@@ -929,6 +928,7 @@ function init_gears() {
                                db.execute("DROP INDEX IF EXISTS articles_feed_id_idx");
                                db.execute("DROP TABLE IF EXISTS version");
                                db.execute("DROP TRIGGER IF EXISTS articles_update_modified");
+                               db.execute("DROP TRIGGER IF EXISTS articles_remove_labelrefs");
                                db.execute("CREATE TABLE IF NOT EXISTS version (schema_version text)");
                                db.execute("INSERT INTO version (schema_version) VALUES (?)", 
                                        [SCHEMA_VERSION]);
@@ -952,9 +952,16 @@ function init_gears() {
                        db.execute("CREATE TRIGGER IF NOT EXISTS articles_update_modified "+
                                "UPDATE OF unread ON articles "+
                                "BEGIN "+
-                               "UPDATE articles SET modified = DATETIME('NOW') WHERE id = old.id; "+
+                               "UPDATE articles SET modified = DATETIME('NOW') WHERE id = old.id AND "+
+                               "old.unread = 1;"+
                                "END;");
 
+                       db.execute("CREATE TRIGGER IF NOT EXISTS articles_remove_labelrefs "+
+                               "DELETE ON articles "+
+                               "BEGIN "+
+                               "DELETE FROM article_labels WHERE id = OLD.id; "+
+                               "END; ");
+
                        Element.show("restartOfflinePic");
 
                }       
@@ -1134,7 +1141,7 @@ function get_local_article_labels(id) {
 
 function label_local_add_article(id, label_id) {
        try {
-               debug("label_local_add_article " + id + " => " + label_id);
+               //debug("label_local_add_article " + id + " => " + label_id);
 
                var rs = db.execute("SELECT COUNT(id) FROM article_labels WHERE "+
                        "id = ? AND label_id = ?", [id, label_id]);