ssb: More incremental profile loading?

This commit is contained in:
Cory McWilliams 2025-04-09 22:08:33 -04:00
parent 6f96d4ce65
commit 5a818d2119
2 changed files with 73 additions and 56 deletions

View File

@ -1,5 +1,5 @@
{ {
"type": "tildefriends-app", "type": "tildefriends-app",
"emoji": "🦀", "emoji": "🦀",
"previous": "&VE+OD1O5xdeiqipvbxXpmatUHu7dTbliuQpFnuZgsGQ=.sha256" "previous": "&h9uzh3gVWy1KWIu6wFYCrBZkVmnQAi7QLAj5iIXffFM=.sha256"
} }

View File

@ -175,11 +175,16 @@ class TfElement extends LitElement {
} }
} }
const k_chunk_size = 1024;
let min_row_id = 0;
console.log('loading about for', ids.length, 'accounts', cache.last_row_id, '=>', max_row_id);
try { try {
while (true) {
let abouts = await tfrpc.rpc.query( let abouts = await tfrpc.rpc.query(
` `
SELECT * FROM (
SELECT SELECT
messages.author, json(messages.content) AS content, messages.sequence messages.rowid AS rowid, messages.author, json(messages.content) AS content, messages.sequence
FROM FROM
messages, messages,
json_each(?1) AS following json_each(?1) AS following
@ -190,23 +195,28 @@ class TfElement extends LitElement {
messages.rowid <= ?4 messages.rowid <= ?4
UNION UNION
SELECT SELECT
messages.author, json(messages.content) AS content, messages.sequence messages.rowid AS rowid, messages.author, json(messages.content) AS content, messages.sequence
FROM FROM
messages, messages,
json_each(?2) AS following json_each(?2) AS following
WHERE WHERE
messages.author = following.value AND messages.author = following.value AND
messages.content ->> 'type' = 'about' AND messages.content ->> 'type' = 'about' AND
messages.rowid > ?6 AND
messages.rowid <= ?4 messages.rowid <= ?4
ORDER BY messages.author, messages.sequence )
ORDER BY rowid LIMIT ?5
`, `,
[ [
JSON.stringify(ids.filter((id) => cache.about[id])), JSON.stringify(ids.filter((id) => cache.about[id])),
JSON.stringify(ids.filter((id) => !cache.about[id])), JSON.stringify(ids.filter((id) => !cache.about[id])),
cache.last_row_id, cache.last_row_id,
max_row_id, max_row_id,
k_chunk_size,
min_row_id,
] ]
); );
let max_seen;
for (let about of abouts) { for (let about of abouts) {
let content = JSON.parse(about.content); let content = JSON.parse(about.content);
if (content.about === about.author) { if (content.about === about.author) {
@ -217,8 +227,11 @@ class TfElement extends LitElement {
content content
); );
} }
max_seen = about.rowid;
} }
cache.last_row_id = max_row_id; console.log('cache =', cache.last_row_id, 'seen =', max_seen, 'max =', max_row_id);
cache.last_row_id = Math.max(cache.last_row_id, max_seen ?? max_row_id);
min_row_id = Math.max(min_row_id, max_seen ?? max_row_id);
let new_cache = JSON.stringify(cache); let new_cache = JSON.stringify(cache);
if (new_cache !== original_cache) { if (new_cache !== original_cache) {
let start_time = new Date(); let start_time = new Date();
@ -234,6 +247,10 @@ class TfElement extends LitElement {
cache.about[id] cache.about[id]
); );
} }
if (cache.last_row_id >= max_row_id) {
break;
}
}
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }