ssb: Still chasing faster loads of the default news query.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 29m59s

This commit is contained in:
Cory McWilliams 2025-04-02 12:44:17 -04:00
parent c128cfc25c
commit 894c72a82f
3 changed files with 13 additions and 5 deletions

View File

@ -1,5 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "🦀",
"previous": "&U/Hy2rgSqwKeF30kKWPUL0qLzXBnxPHxQS5OgfxwZG8=.sha256"
"previous": "&BNj/9Tct9Iw03fAx0TSjCI5Cm1EizcmTj6JZm3bZpB4=.sha256"
}

View File

@ -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`
);
}

View File

@ -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,"