From 894c72a82fcac41b2b784cd753529f6340bdd066 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 2 Apr 2025 12:44:17 -0400 Subject: [PATCH] ssb: Still chasing faster loads of the default news query. --- apps/ssb.json | 2 +- apps/ssb/tf-tab-news-feed.js | 10 ++++++++-- src/ssb.db.c | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/ssb.json b/apps/ssb.json index 124cbd66..161f5e82 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🦀", - "previous": "&U/Hy2rgSqwKeF30kKWPUL0qLzXBnxPHxQS5OgfxwZG8=.sha256" + "previous": "&BNj/9Tct9Iw03fAx0TSjCI5Cm1EizcmTj6JZm3bZpB4=.sha256" } diff --git a/apps/ssb/tf-tab-news-feed.js b/apps/ssb/tf-tab-news-feed.js index 13bf33c8..a93f220a 100644 --- a/apps/ssb/tf-tab-news-feed.js +++ b/apps/ssb/tf-tab-news-feed.js @@ -159,13 +159,15 @@ class TfTabNewsFeedElement extends LitElement { ); result = (await this.decrypt(result)).filter((x) => x.decrypted); } else { + let st = new Date(); result = await tfrpc.rpc.query( ` WITH all_news AS ( SELECT messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature FROM messages - JOIN json_each(?) AS following ON messages.author = following.value), + JOIN json_each(?) AS following ON messages.author = following.value + ), news AS ( SELECT * FROM all_news WHERE all_news.timestamp < ?3 AND (?2 IS NULL OR all_news.timestamp >= ?2) @@ -183,6 +185,10 @@ class TfTabNewsFeedElement extends LitElement { `, [JSON.stringify(this.following), start_time, end_time] ); + let et = new Date(); + console.log( + `just the load of ${result.length} rows = ${(et - st) / 1000} following=${this.following.length} st=${start_time} et=${end_time}` + ); } this.time_loading = undefined; return result; @@ -308,7 +314,7 @@ class TfTabNewsFeedElement extends LitElement { this.messages = this.merge_messages(this.messages, messages); this.time_loading = undefined; console.log( - `loading messages done for ${self.whoami} in ${(new Date() - start_time) / 1000}s` + `loading ${messages.length} messages done for ${self.whoami} in ${(new Date() - start_time) / 1000}s` ); } diff --git a/src/ssb.db.c b/src/ssb.db.c index 6c36004a..31ca7104 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -176,17 +176,19 @@ void tf_ssb_db_init(tf_ssb_t* ssb) _tf_ssb_db_exec(db, "ALTER TABLE messages RENAME COLUMN sequence_before_author TO flags"); } - _tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_id_index ON messages (id)"); + _tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_id_author_index ON messages (id, author)"); _tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_author_sequence_index ON messages (author, sequence)"); _tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_author_timestamp_index ON messages (author, timestamp)"); _tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_timestamp_index ON messages (timestamp)"); _tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_type_timestamp_index ON messages (content ->> 'type', timestamp)"); _tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_size_by_author_index ON messages (author, length(content))"); - _tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_type_author_channel_root_rowid_index ON messages (author, content ->> 'type', content ->> 'channel', content ->> 'root')"); + _tf_ssb_db_exec( + db, "CREATE INDEX IF NOT EXISTS messages_type_author_channel_root_rowid_index ON messages (author, content ->> 'type', content ->> 'channel', content ->> 'root')"); _tf_ssb_db_exec(db, "DROP INDEX IF EXISTS messages_type_author_channel_index"); _tf_ssb_db_exec(db, "DROP INDEX IF EXISTS messages_author_id_index"); _tf_ssb_db_exec(db, "DROP INDEX IF EXISTS messages_by_author_index"); _tf_ssb_db_exec(db, "DROP INDEX IF EXISTS messages_timestamp_author_index"); + _tf_ssb_db_exec(db, "DROP INDEX IF EXISTS messages_id_index"); _tf_ssb_db_exec(db, "CREATE TABLE IF NOT EXISTS blobs (" " id TEXT PRIMARY KEY,"