offline: update articles.modified on marked unread using trigger

master
Andrew Dolgov 16 years ago
parent 79645416fe
commit 55852afa57

@ -1,4 +1,4 @@
var SCHEMA_VERSION = 9; var SCHEMA_VERSION = 10;
var offline_mode = false; var offline_mode = false;
var store = false; var store = false;
@ -670,18 +670,15 @@ function offline_download_parse(stage, transport) {
articles_found++; articles_found++;
if (a) { if (a) {
var date = new Date();
var ts = Math.round(date.getTime() / 1000);
db.execute("DELETE FROM articles WHERE id = ?", [a.id]); db.execute("DELETE FROM articles WHERE id = ?", [a.id]);
db.execute("DELETE FROM article_labels WHERE id = ?", [a.id]); db.execute("DELETE FROM article_labels WHERE id = ?", [a.id]);
db.execute("INSERT INTO articles "+ db.execute("INSERT INTO articles "+
"(id, feed_id, title, link, guid, updated, content, "+ "(id, feed_id, title, link, guid, updated, content, "+
"unread, marked, tags, added, comments) "+ "unread, marked, tags, comments) "+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
[a.id, a.feed_id, a.title, a.link, a.guid, a.updated, [a.id, a.feed_id, a.title, a.link, a.guid, a.updated,
a.content, a.unread, a.marked, a.tags, ts, a.content, a.unread, a.marked, a.tags,
a.comments]); a.comments]);
if (a.labels.length > 0) { if (a.labels.length > 0) {
@ -931,6 +928,7 @@ function init_gears() {
db.execute("DROP INDEX IF EXISTS articles_unread_idx"); db.execute("DROP INDEX IF EXISTS articles_unread_idx");
db.execute("DROP INDEX IF EXISTS articles_feed_id_idx"); db.execute("DROP INDEX IF EXISTS articles_feed_id_idx");
db.execute("DROP TABLE IF EXISTS version"); db.execute("DROP TABLE IF EXISTS version");
db.execute("DROP TRIGGER IF EXISTS articles_update_modified");
db.execute("CREATE TABLE IF NOT EXISTS version (schema_version text)"); db.execute("CREATE TABLE IF NOT EXISTS version (schema_version text)");
db.execute("INSERT INTO version (schema_version) VALUES (?)", db.execute("INSERT INTO version (schema_version) VALUES (?)",
[SCHEMA_VERSION]); [SCHEMA_VERSION]);
@ -943,7 +941,7 @@ function init_gears() {
db.execute("CREATE TABLE IF NOT EXISTS categories (id integer, title text, collapsed integer)"); db.execute("CREATE TABLE IF NOT EXISTS categories (id integer, title text, collapsed integer)");
db.execute("CREATE TABLE IF NOT EXISTS labels (id integer, caption text, fg_color text, bg_color text)"); db.execute("CREATE TABLE IF NOT EXISTS labels (id integer, caption text, fg_color text, bg_color text)");
db.execute("CREATE TABLE IF NOT EXISTS article_labels (id integer, label_id integer)"); db.execute("CREATE TABLE IF NOT EXISTS article_labels (id integer, label_id integer)");
db.execute("CREATE TABLE IF NOT EXISTS articles (id integer, feed_id integer, title text, link text, guid text, updated text, content text, tags text, unread text, marked text, added text, comments text)"); db.execute("CREATE TABLE IF NOT EXISTS articles (id integer, feed_id integer, title text, link text, guid text, updated timestamp, content text, tags text, unread integer, marked integer, added text, modified timestamp, comments text)");
db.execute("CREATE INDEX IF NOT EXISTS articles_unread_idx ON articles(unread)"); db.execute("CREATE INDEX IF NOT EXISTS articles_unread_idx ON articles(unread)");
db.execute("CREATE INDEX IF NOT EXISTS article_labels_label_id_idx ON article_labels(label_id)"); db.execute("CREATE INDEX IF NOT EXISTS article_labels_label_id_idx ON article_labels(label_id)");
@ -951,6 +949,12 @@ function init_gears() {
db.execute("DELETE FROM cache WHERE id LIKE 'F:%' OR id LIKE 'C:%'"); db.execute("DELETE FROM cache WHERE id LIKE 'F:%' OR id LIKE 'C:%'");
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; "+
"END;");
Element.show("restartOfflinePic"); Element.show("restartOfflinePic");
} }

Loading…
Cancel
Save