diff --git a/inc/lektor/database.h b/inc/lektor/database.h index e0975dc717b91feaeb7fcaed74f85d66a7a5d3de..3c9601400862dae0f1722fde761e677f0a4073a7 100644 --- a/inc/lektor/database.h +++ b/inc/lektor/database.h @@ -24,6 +24,7 @@ struct lkt_queue_state { long database_get_timestamp(volatile sqlite3 *db); void database_stamp(volatile sqlite3 *db); +void database_updated(volatile sqlite3 *db); /* Open correctly a database for lektor. */ bool database_new (sqlite3 **db); diff --git a/scripts/init.sql b/scripts/init.sql index 9646d53ce0d21006a1649e5df133e0b5ec41857b..21bffe9af33706a6d66816515760044f95c59789 100644 --- a/scripts/init.sql +++ b/scripts/init.sql @@ -121,12 +121,16 @@ CREATE TABLE IF NOT EXISTS 'stickers.plt' -- Some useful values: -- last_update is the timestamp of the last time the table of kara has been --- updated. This is so lektor doesn't have to read all kara in the filesystem, +-- updated. This is so lektor doesn't have to read all kara in the filesystem, -- just the new ones (where their modified timestamp is greater than --- last_update). If last_update is NULL then the database is empty. +-- last_update). If last_update is NULL then the database is empty. +-- the last_end_update is here to mark a synchronisation point. Multiple +-- update can be done (updating last_update), but a general update can be +-- in progress. CREATE TABLE IF NOT EXISTS misc - ( id INTEGER PRIMARY KEY DEFAULT 42 CHECK(id = 42) - , last_update INTEGER + ( id INTEGER PRIMARY KEY DEFAULT 42 CHECK(id = 42) + , last_update INTEGER + , last_end_update INTEGER ); INSERT OR REPLACE INTO misc (id) VALUES (42); diff --git a/src/database/open.c b/src/database/open.c index 12c09489da2b72b7c1428b36152d2e44b7dc715c..61414c90395852fbf6838cd4428b46f8a7428688 100644 --- a/src/database/open.c +++ b/src/database/open.c @@ -213,3 +213,11 @@ database_stamp(volatile sqlite3 *db) error: return; } + +void +database_updated(volatile sqlite3 *db) +{ + SQLITE_EXEC(db, "UPDATE misc SET last_end_update = strftime('%s','now');", error); +error: + return; +} diff --git a/src/database/update.c b/src/database/update.c index 4c677ed529ce7b8ce6b1677a7d1e8a29951f7d9d..f4d992e4963742ae0d0f13e9a565df961b9f1250 100644 --- a/src/database/update.c +++ b/src/database/update.c @@ -146,6 +146,7 @@ database_update(sqlite3 *db, const char *kara_dir) } LOG_INFO("Passed directory '%s'", kara_dir); + database_updated(db); closedir(d); return true; } diff --git a/src/net/downloader.c b/src/net/downloader.c index b4d8d328fe3f0dd41142335bc3ca234e7ce0a7a3..5e18a28ded5b4e741f017d0f294358ee141c7891 100644 --- a/src/net/downloader.c +++ b/src/net/downloader.c @@ -472,6 +472,7 @@ __repo_get_all_id_async(void *arg) __handle_got_json(repo->db, repo, json); LOG_INFO_SCT("REPO", "%s", "Finished to download and insert kara list"); json_object_put(json); + database_updated(repo->db); return NULL; }