From 3e5abf3a4dfffb618fe3666bfb31d7a001cb4fe7 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 27 Jul 2023 12:22:37 +0000 Subject: [PATCH] Enable auto vacuum. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4372 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- Makefile | 2 +- src/ssb.db.c | 20 +++++++++++++++++++- src/ssb.rpc.c | 5 +---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index e8b70027..74b1513a 100644 --- a/Makefile +++ b/Makefile @@ -270,7 +270,7 @@ $(SQLITE_OBJS): CFLAGS += \ -DSQLITE_ENABLE_FTS5 \ -DSQLITE_ENABLE_JSON1 \ -DSQLITE_LIKE_DOESNT_MATCH_BLOBS \ - -DSQLITE_MAX_ATTACHED=0 \ + -DSQLITE_MAX_ATTACHED=1 \ -DSQLITE_MAX_COLUMN=100 \ -DSQLITE_MAX_COMPOUND_SELECT=300 \ -DSQLITE_MAX_EXPR_DEPTH=40 \ diff --git a/src/ssb.db.c b/src/ssb.db.c index 207db0d3..c8fd623e 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -77,6 +77,25 @@ void tf_ssb_db_init(tf_ssb_t* ssb) { sqlite3* db = tf_ssb_acquire_db_writer(ssb); _tf_ssb_db_init_internal(db); + + sqlite3_stmt* statement = NULL; + int auto_vacuum = 0; + if (sqlite3_prepare(db, "PRAGMA auto_vacuum", -1, &statement, NULL) == SQLITE_OK) + { + if (sqlite3_step(statement) == SQLITE_ROW) + { + auto_vacuum = sqlite3_column_int(statement, 0); + } + sqlite3_finalize(statement); + } + if (auto_vacuum != 1 /* FULL */) + { + tf_printf("Enabling auto-vacuum and performing full vacuum.\n"); + _tf_ssb_db_exec(db, "PRAGMA auto_vacuum = FULL"); + _tf_ssb_db_exec(db, "VACUUM main"); + tf_printf("All clean.\n"); + } + _tf_ssb_db_exec(db, "CREATE TABLE IF NOT EXISTS messages (" " author TEXT," @@ -196,7 +215,6 @@ void tf_ssb_db_init(tf_ssb_t* ssb) bool need_add_sequence_before_author = true; bool need_convert_timestamp_to_real = false; - sqlite3_stmt* statement = NULL; if (sqlite3_prepare(db, "PRAGMA table_info(messages)", -1, &statement, NULL) == SQLITE_OK) { int result = SQLITE_OK; diff --git a/src/ssb.rpc.c b/src/ssb.rpc.c index 690d4449..7533a1ce 100644 --- a/src/ssb.rpc.c +++ b/src/ssb.rpc.c @@ -1188,10 +1188,7 @@ static void _tf_ssb_rpc_delete_blobs_work(uv_work_t* work) tf_ssb_release_db_writer(ssb, db); int64_t duration_ms = (uv_hrtime() - start_ns) / 1000000LL; tf_printf("Deleted %d blobs in %d ms.\n", deleted, (int)duration_ms); - if (deleted) - { - _tf_ssb_rpc_start_delete_blobs(ssb, (int)duration_ms); - } + _tf_ssb_rpc_start_delete_blobs(ssb, deleted ? (int)duration_ms : (15 * 60 * 1000)); } static void _tf_ssb_rpc_delete_blobs_after_work(uv_work_t* work, int status)