From 4de53b9926feca4add3479c93de5f6f1783e3c4c Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 7 May 2025 18:15:33 -0400 Subject: [PATCH] core: sqlite checkpoint tweaks. Switch the periodic checkpoint to passive mode. Truncate mode was painful on mobile. I'm seeing it succeed often enough that we don't grow indefinitely. Also fix the print. --- apps/ssb/tf-app.js | 21 +++++++++++++++------ apps/welcome/index.html | 6 +++--- src/ssb.rpc.c | 6 +++--- src/ssb.tests.c | 6 +----- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/apps/ssb/tf-app.js b/apps/ssb/tf-app.js index 41eb5b36..f736c36b 100644 --- a/apps/ssb/tf-app.js +++ b/apps/ssb/tf-app.js @@ -191,8 +191,15 @@ class TfElement extends LitElement { try { while (true) { let max_seen; - for (let account_chunk = 0; account_chunk < ids.length; account_chunk += k_account_chunk_size) { - let ids_chunk = ids.slice(account_chunk, account_chunk + k_account_chunk_size); + for ( + let account_chunk = 0; + account_chunk < ids.length; + account_chunk += k_account_chunk_size + ) { + let ids_chunk = ids.slice( + account_chunk, + account_chunk + k_account_chunk_size + ); let abouts = await tfrpc.rpc.query( ` WITH @@ -464,16 +471,18 @@ class TfElement extends LitElement { } async load_recent_reactions() { - this.recent_reactions = (await tfrpc.rpc.query( - ` + this.recent_reactions = ( + await tfrpc.rpc.query( + ` SELECT DISTINCT content ->> '$.vote.expression' AS value FROM messages WHERE author = ? AND content ->> '$.type' = 'vote' ORDER BY timestamp DESC LIMIT 10 `, - [this.whoami] - )).map((x) => x.value); + [this.whoami] + ) + ).map((x) => x.value); } async load() { diff --git a/apps/welcome/index.html b/apps/welcome/index.html index d0aeea35..b4ba408e 100644 --- a/apps/welcome/index.html +++ b/apps/welcome/index.html @@ -234,9 +234,9 @@

Built the Old Fashioned Way

- Tilde Friends strives to use only simple and widely adopted - dependencies in order to keep it easy to build for all sorts of - platforms and maintainable for a very long time. + Tilde Friends strives to use only simple and widely adopted dependencies + in order to keep it easy to build for all sorts of platforms and + maintainable for a very long time.

Though of course for building Tilde Friends apps, you are free to use diff --git a/src/ssb.rpc.c b/src/ssb.rpc.c index ce2306ec..3639665f 100644 --- a/src/ssb.rpc.c +++ b/src/ssb.rpc.c @@ -1469,9 +1469,9 @@ static void _tf_ssb_rpc_checkpoint(tf_ssb_t* ssb) sqlite3* db = tf_ssb_acquire_db_writer(ssb); int log = 0; int checkpointed = 0; - if (sqlite3_wal_checkpoint_v2(db, NULL, SQLITE_CHECKPOINT_TRUNCATE, &log, &checkpointed) == SQLITE_OK) + if (sqlite3_wal_checkpoint_v2(db, NULL, SQLITE_CHECKPOINT_PASSIVE, &log, &checkpointed) == SQLITE_OK) { - tf_printf("Checkpointed %d frames in %d ms. Log is now %d frames.\n", (int)((uv_hrtime() - checkpoint_start_ms) / 1000000LL), checkpointed, log); + tf_printf("Checkpointed %d frames in %d ms. Log is now %d frames.\n", checkpointed, (int)((uv_hrtime() - checkpoint_start_ms) / 1000000LL), log); } else { @@ -1541,7 +1541,7 @@ static void _tf_ssb_rpc_delete_blobs_work(tf_ssb_t* ssb, void* user_data) static void _tf_ssb_rpc_delete_blobs_after_work(tf_ssb_t* ssb, int status, void* user_data) { delete_t* delete = user_data; - _tf_ssb_rpc_start_delete_blobs(ssb, delete->deleted ? (int)delete->duration_ms : (15 * 60 * 1000)); + _tf_ssb_rpc_start_delete_blobs(ssb, delete->deleted ? (int)delete->duration_ms : (5 * 60 * 1000)); tf_free(delete); } diff --git a/src/ssb.tests.c b/src/ssb.tests.c index 6195c4b4..98ccb273 100644 --- a/src/ssb.tests.c +++ b/src/ssb.tests.c @@ -1532,11 +1532,7 @@ static char* _subprocess_check_output(const char* command) static bool _isspace(char c) { - return - c == ' ' || - c == '\t' || - c == '\r' || - c == '\n'; + return c == ' ' || c == '\t' || c == '\r' || c == '\n'; } static char* _trim(char* p)