ssb: Rearrange indexes for an overall faster load on mobile for me. Tidy up some things along the way.
Some checks are pending
Build Tilde Friends / Build-All (push) Has started running

This commit is contained in:
Cory McWilliams 2025-03-30 12:16:23 -04:00
parent 9462521287
commit 1011e0026b
5 changed files with 16 additions and 19 deletions

View File

@ -1,5 +1,5 @@
{ {
"type": "tildefriends-app", "type": "tildefriends-app",
"emoji": "🦀", "emoji": "🦀",
"previous": "&wOd/+1l5wpywBlfxC1Lm0i+HhYidrgSfrn9LRX7qy2w=.sha256" "previous": "&1odTdQMYLeIjmLDEIAxcoabT7D5cXYWcDO4nNJH9KRY=.sha256"
} }

View File

@ -184,9 +184,9 @@ class TfElement extends LitElement {
json_each(?1) AS following json_each(?1) AS following
WHERE WHERE
messages.author = following.value AND messages.author = following.value AND
messages.content ->> 'type' = 'about' AND
messages.rowid > ?3 AND messages.rowid > ?3 AND
messages.rowid <= ?4 AND messages.rowid <= ?4
json_extract(messages.content, '$.type') = 'about'
UNION UNION
SELECT SELECT
messages.author, json(messages.content) AS content, messages.sequence messages.author, json(messages.content) AS content, messages.sequence
@ -195,8 +195,8 @@ class TfElement extends LitElement {
json_each(?2) AS following json_each(?2) AS following
WHERE WHERE
messages.author = following.value AND messages.author = following.value AND
messages.rowid <= ?4 AND messages.content ->> 'type' = 'about' AND
json_extract(messages.content, '$.type') = 'about' messages.rowid <= ?4
ORDER BY messages.author, messages.sequence ORDER BY messages.author, messages.sequence
`, `,
[ [
@ -382,7 +382,6 @@ class TfElement extends LitElement {
'🔐': latest[0], '🔐': latest[0],
}); });
console.log('private took', (new Date() - start_time) / 1000.0); console.log('private took', (new Date() - start_time) / 1000.0);
console.log(latest);
self.private_messages = latest[1]; self.private_messages = latest[1];
}); });
} }

View File

@ -172,17 +172,13 @@ class TfTabNewsFeedElement extends LitElement {
WHERE (?2 IS NULL OR all_news.timestamp >= ?2) AND all_news.timestamp < ?3 WHERE (?2 IS NULL OR all_news.timestamp >= ?2) AND all_news.timestamp < ?3
ORDER BY timestamp DESC LIMIT 20 ORDER BY timestamp DESC LIMIT 20
) )
SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature
FROM news
JOIN messages_refs ON news.id = messages_refs.ref
JOIN messages ON messages_refs.message = messages.id
UNION
SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature
FROM news
JOIN messages_refs ON news.id = messages_refs.message
JOIN messages ON messages_refs.ref = messages.id
UNION
SELECT TRUE AS is_primary, news.* FROM news SELECT TRUE AS is_primary, news.* FROM news
UNION
SELECT FALSE AS is_primary, messages.rowid, messages.id, messages.previous, messages.author, messages.sequence, messages.timestamp, messages.hash, json(messages.content) AS content, messages.signature
FROM news
JOIN messages_refs refs_in ON news.id = refs_in.ref
JOIN messages_refs refs_out ON news.id = refs_out.message
JOIN messages ON (messages.id = refs_out.message OR messages.id = refs_in.ref)
`, `,
[JSON.stringify(this.following), start_time, end_time] [JSON.stringify(this.following), start_time, end_time]
); );

View File

@ -347,7 +347,6 @@ public class TildeFriendsActivity extends Activity {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
e.printStackTrace(); e.printStackTrace();
} catch (java.io.FileNotFoundException e) { } catch (java.io.FileNotFoundException e) {
Log.w("tildefriends", "Port file does not yet exist.");
} catch (java.io.IOException e) { } catch (java.io.IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -176,13 +176,16 @@ 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, "ALTER TABLE messages RENAME COLUMN sequence_before_author TO flags");
} }
_tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_author_id_index ON messages (author, id)"); _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_author_sequence_index ON messages (author, sequence)"); _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_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_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_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_size_by_author_index ON messages (author, length(content))");
_tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_type_author_channel_index ON messages (content ->> 'type', author, content ->> 'channel');"); _tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS messages_type_author_channel_index ON messages (content ->> 'type', author, content ->> 'channel')");
_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, _tf_ssb_db_exec(db,
"CREATE TABLE IF NOT EXISTS blobs (" "CREATE TABLE IF NOT EXISTS blobs ("
" id TEXT PRIMARY KEY," " id TEXT PRIMARY KEY,"