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)