]> git.wh0rd.org Git - tt-rss.git/commitdiff
experimental gears cache work
authorAndrew Dolgov <fox@bah.org.ru>
Mon, 2 Feb 2009 12:02:10 +0000 (15:02 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Mon, 2 Feb 2009 12:02:10 +0000 (15:02 +0300)
manifest.json
tt-rss.js
viewfeed.js

index e349d96005d30620628cf587d2c753f9c6ab96c7..6dd6ecc9b0dbe05463407276699b472521571e14 100644 (file)
@@ -1,9 +1,18 @@
 {
   "betaManifestVersion": 1,
-  "version": "my_version_string",
+  "version": "0",
   "entries": [
-      { "url": "go_offline.html"},
-      { "url": "go_offline.js"},
-      { "url": "../gears_init.js"}
+      { "url": "tt-rss.php"},
+      { "url": "tt-rss.css"},
+      { "url": "viewfeed.js"},
+      { "url": "feedlist.js"},
+      { "url": "functions.js"},
+      { "url": "tt-rss.js"},
+      { "url": "lib/scriptaculous/effects.js"},
+      { "url": "lib/scriptaculous/controls.js"},
+      { "url": "lib/scriptaculous/dragdrop.js"},
+      { "url": "lib/scriptaculous/scriptaculous.js"},
+      { "url": "lib/prototype.js"},
+      { "url": "gears_init.js"}
     ]
-}
\ No newline at end of file
+}
index 17e33bf85f723ac35df41593b1f5e4fd3e96ab14..d49eaa6be472c9d9dacd5023593c215131f74d21 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -19,6 +19,10 @@ var ver_offset = 0;
 var hor_offset = 0;
 var feeds_sort_by_unread = false;
 var feedlist_sortable_enabled = false;
+var offline_mode = false;
+var store = false;
+var localServer = false;
+var db = false;
 
 function activeFeedIsCat() {
        return _active_feed_is_cat;
@@ -131,7 +135,11 @@ function backend_sanity_check_callback(transport) {
                }
 
                if (!transport.responseXML) {
-                       fatalError(3, "Sanity check: Received reply is not XML", transport.responseText);
+                       if (!google.gears) {
+                               fatalError(3, "Sanity check: Received reply is not XML", transport.responseText);
+                       } else {
+                               init_offline();
+                       }
                        return;
                }
 
@@ -369,6 +377,8 @@ function init() {
                if (arguments.callee.done) return;
                arguments.callee.done = true;           
 
+               init_gears();
+
                disableContainerChildren("headlinesToolbar", true);
 
                Form.disable("main_toolbar_form");
@@ -1451,3 +1461,31 @@ function feedBrowserSubscribe() {
        }
 }
 
+function init_gears() {
+       try {
+
+               if (google.gears) {
+                       localServer = google.gears.factory.create("beta.localserver");
+                       store = localServer.createManagedStore("tt-rss");
+                       db = google.gears.factory.create('beta.database');
+                       db.open('tt-rss');
+
+                       db.execute("CREATE TABLE IF NOT EXISTS cache (id text, article text, param text, added text)");
+               }       
+
+       } catch (e) {
+               exception_error("init_gears", e);
+       }
+}
+
+function init_offline() {
+       try {
+               offline_mode = true;
+
+               remove_splash();
+
+       } catch (e) {
+               exception_error("init_offline", e);
+       }
+}
+
index 828a2e89ce0f9239b7c1f29c2d38ba4decbfbcab..615f366f3dca04edb716a07363b8f5654e384c45 100644 (file)
@@ -1466,65 +1466,116 @@ function cdmWatchdog() {
 
 
 function cache_inject(id, article, param) {
-       if (!cache_check_param(id, param)) {
-               debug("cache_article: miss: " + id + " [p=" + param + "]");
-
-               var cache_obj = new Array();
-
-               cache_obj["id"] = id;
-               cache_obj["data"] = article;
-               cache_obj["param"] = param;
+       try {
+               if (!cache_check_param(id, param)) {
+                       debug("cache_article: miss: " + id + " [p=" + param + "]");
+       
+       
+                       if (db) {
 
-               article_cache.push(cache_obj);
+                          var date = new Date();
+                     var ts = Math.round(date.getTime() / 1000);
 
-       } else {
-               debug("cache_article: hit: " + id + " [p=" + param + "]");
+                               db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
+                                       [id, article, param, ts]);                              
+                       } else {
+       
+                               var cache_obj = new Array();
+       
+                               cache_obj["id"] = id;
+                               cache_obj["data"] = article;
+                               cache_obj["param"] = param;
+       
+                               article_cache.push(cache_obj);
+                       }
+       
+               } else {
+                       debug("cache_article: hit: " + id + " [p=" + param + "]");
+               }
+       } catch (e) {   
+               exception_error("cache_inject", e);
        }
 }
 
 function cache_find(id) {
-       for (var i = 0; i < article_cache.length; i++) {
-               if (article_cache[i]["id"] == id) {
-                       return article_cache[i]["data"];
+
+       if (db) {
+
+       } else {
+               for (var i = 0; i < article_cache.length; i++) {
+                       if (article_cache[i]["id"] == id) {
+                               return article_cache[i]["data"];
+                       }
                }
        }
        return false;
 }
 
 function cache_find_param(id, param) {
-       for (var i = 0; i < article_cache.length; i++) {
-               if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
-                       return article_cache[i]["data"];
+
+       if (db) {
+               var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
+                       [id, param]);
+
+               if (rs.isValidRow()) {
+                       return rs.field(0);
+               }
+
+       } else {
+               for (var i = 0; i < article_cache.length; i++) {
+                       if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
+                               return article_cache[i]["data"];
+                       }
                }
        }
        return false;
 }
 
 function cache_check(id) {
-       for (var i = 0; i < article_cache.length; i++) {
-               if (article_cache[i]["id"] == id) {
-                       return true;
+
+       if (db) {
+               var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
+                       [id]);
+
+               if (rs.isValidRow()) {
+                       return rs.field(0) != "0";
+               }
+
+       } else {
+               for (var i = 0; i < article_cache.length; i++) {
+                       if (article_cache[i]["id"] == id) {
+                               return true;
+                       }
                }
        }
        return false;
 }
 
 function cache_check_param(id, param) {
-       for (var i = 0; i < article_cache.length; i++) {
 
-//             debug("cache_check_param " + article_cache[i]["id"] + ":" + 
-//                     article_cache[i]["param"] + " vs " + id + ":" + param);
+       if (db) {
+               var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
+                       [id, param]);
 
-               if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
-                       return true;
+               if (rs.isValidRow()) {
+                       return rs.field(0) != "0";
+               }
+
+       } else {
+               for (var i = 0; i < article_cache.length; i++) {
+                       if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
+                               return true;
+                       }
                }
        }
        return false;
 }
 
 function cache_expire() {
-       while (article_cache.length > 25) {
-               article_cache.shift();
+       if (!db) {
+               while (article_cache.length > 25) {
+                       article_cache.shift();
+               }
        }
 }
 
@@ -1533,18 +1584,25 @@ function cache_empty() {
 }
 
 function cache_invalidate(id) {
-       var i = 0
-
        try {   
 
-               while (i < article_cache.length) {
-                       if (article_cache[i]["id"] == id) {
-                               debug("cache_invalidate: removed id " + id);
-                               article_cache.splice(i, 1);
-                               return true;
+               if (db) {
+                       rs = db.execute("DELETE FROM cache WHERE id = ?", [id]);
+                       return rs.rowsAffected != 0;
+               } else {
+
+                       var i = 0
+
+                       while (i < article_cache.length) {
+                               if (article_cache[i]["id"] == id) {
+                                       debug("cache_invalidate: removed id " + id);
+                                       article_cache.splice(i, 1);
+                                       return true;
+                               }
+                               i++;
                        }
-                       i++;
                }
+
                debug("cache_invalidate: id not found: " + id);
                return false;
        } catch (e) {