1
0
mirror of https://tt-rss.org/git/tt-rss.git synced 2024-06-26 11:59:02 +02:00

experimental gears cache work

This commit is contained in:
Andrew Dolgov 2009-02-02 15:02:10 +03:00
parent 3e2f2a0b7d
commit fb456d28f2
3 changed files with 146 additions and 41 deletions

View File

@ -1,9 +1,18 @@
{ {
"betaManifestVersion": 1, "betaManifestVersion": 1,
"version": "my_version_string", "version": "0",
"entries": [ "entries": [
{ "url": "go_offline.html"}, { "url": "tt-rss.php"},
{ "url": "go_offline.js"}, { "url": "tt-rss.css"},
{ "url": "../gears_init.js"} { "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"}
] ]
} }

View File

@ -19,6 +19,10 @@ var ver_offset = 0;
var hor_offset = 0; var hor_offset = 0;
var feeds_sort_by_unread = false; var feeds_sort_by_unread = false;
var feedlist_sortable_enabled = false; var feedlist_sortable_enabled = false;
var offline_mode = false;
var store = false;
var localServer = false;
var db = false;
function activeFeedIsCat() { function activeFeedIsCat() {
return _active_feed_is_cat; return _active_feed_is_cat;
@ -131,7 +135,11 @@ function backend_sanity_check_callback(transport) {
} }
if (!transport.responseXML) { 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; return;
} }
@ -369,6 +377,8 @@ function init() {
if (arguments.callee.done) return; if (arguments.callee.done) return;
arguments.callee.done = true; arguments.callee.done = true;
init_gears();
disableContainerChildren("headlinesToolbar", true); disableContainerChildren("headlinesToolbar", true);
Form.disable("main_toolbar_form"); 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);
}
}

View File

@ -1466,65 +1466,116 @@ function cdmWatchdog() {
function cache_inject(id, article, param) { function cache_inject(id, article, param) {
if (!cache_check_param(id, param)) { try {
debug("cache_article: miss: " + id + " [p=" + param + "]"); if (!cache_check_param(id, param)) {
debug("cache_article: miss: " + id + " [p=" + param + "]");
if (db) {
var cache_obj = new Array(); var date = new Date();
var ts = Math.round(date.getTime() / 1000);
cache_obj["id"] = id; db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
cache_obj["data"] = article; [id, article, param, ts]);
cache_obj["param"] = param; } else {
article_cache.push(cache_obj); var cache_obj = new Array();
} else { cache_obj["id"] = id;
debug("cache_article: hit: " + id + " [p=" + param + "]"); 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) { function cache_find(id) {
for (var i = 0; i < article_cache.length; i++) {
if (article_cache[i]["id"] == id) { if (db) {
return article_cache[i]["data"];
} else {
for (var i = 0; i < article_cache.length; i++) {
if (article_cache[i]["id"] == id) {
return article_cache[i]["data"];
}
} }
} }
return false; return false;
} }
function cache_find_param(id, param) { 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) { if (db) {
return article_cache[i]["data"]; 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; return false;
} }
function cache_check(id) { function cache_check(id) {
for (var i = 0; i < article_cache.length; i++) {
if (article_cache[i]["id"] == id) { if (db) {
return true; 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; return false;
} }
function cache_check_param(id, param) { function cache_check_param(id, param) {
for (var i = 0; i < article_cache.length; i++) {
// debug("cache_check_param " + article_cache[i]["id"] + ":" + if (db) {
// article_cache[i]["param"] + " vs " + id + ":" + param); 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) { if (rs.isValidRow()) {
return true; 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; return false;
} }
function cache_expire() { function cache_expire() {
while (article_cache.length > 25) { if (!db) {
article_cache.shift(); while (article_cache.length > 25) {
article_cache.shift();
}
} }
} }
@ -1533,18 +1584,25 @@ function cache_empty() {
} }
function cache_invalidate(id) { function cache_invalidate(id) {
var i = 0
try { try {
while (i < article_cache.length) { if (db) {
if (article_cache[i]["id"] == id) { rs = db.execute("DELETE FROM cache WHERE id = ?", [id]);
debug("cache_invalidate: removed id " + id); return rs.rowsAffected != 0;
article_cache.splice(i, 1); } else {
return true;
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); debug("cache_invalidate: id not found: " + id);
return false; return false;
} catch (e) { } catch (e) {