ssb: More incremental profile loading?
This commit is contained in:
parent
6f96d4ce65
commit
5a818d2119
@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "tildefriends-app",
|
||||
"emoji": "🦀",
|
||||
"previous": "&VE+OD1O5xdeiqipvbxXpmatUHu7dTbliuQpFnuZgsGQ=.sha256"
|
||||
"previous": "&h9uzh3gVWy1KWIu6wFYCrBZkVmnQAi7QLAj5iIXffFM=.sha256"
|
||||
}
|
||||
|
@ -175,64 +175,81 @@ 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 {
|
||||
let abouts = await tfrpc.rpc.query(
|
||||
`
|
||||
SELECT
|
||||
messages.author, json(messages.content) AS content, messages.sequence
|
||||
FROM
|
||||
messages,
|
||||
json_each(?1) AS following
|
||||
WHERE
|
||||
messages.author = following.value AND
|
||||
messages.content ->> 'type' = 'about' AND
|
||||
messages.rowid > ?3 AND
|
||||
messages.rowid <= ?4
|
||||
UNION
|
||||
SELECT
|
||||
messages.author, json(messages.content) AS content, messages.sequence
|
||||
FROM
|
||||
messages,
|
||||
json_each(?2) AS following
|
||||
WHERE
|
||||
messages.author = following.value AND
|
||||
messages.content ->> 'type' = 'about' AND
|
||||
messages.rowid <= ?4
|
||||
ORDER BY messages.author, messages.sequence
|
||||
`,
|
||||
[
|
||||
JSON.stringify(ids.filter((id) => cache.about[id])),
|
||||
JSON.stringify(ids.filter((id) => !cache.about[id])),
|
||||
cache.last_row_id,
|
||||
max_row_id,
|
||||
]
|
||||
);
|
||||
for (let about of abouts) {
|
||||
let content = JSON.parse(about.content);
|
||||
if (content.about === about.author) {
|
||||
delete content.type;
|
||||
delete content.about;
|
||||
cache.about[about.author] = Object.assign(
|
||||
cache.about[about.author] || {},
|
||||
content
|
||||
while (true) {
|
||||
let abouts = await tfrpc.rpc.query(
|
||||
`
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
messages.rowid AS rowid, messages.author, json(messages.content) AS content, messages.sequence
|
||||
FROM
|
||||
messages,
|
||||
json_each(?1) AS following
|
||||
WHERE
|
||||
messages.author = following.value AND
|
||||
messages.content ->> 'type' = 'about' AND
|
||||
messages.rowid > ?3 AND
|
||||
messages.rowid <= ?4
|
||||
UNION
|
||||
SELECT
|
||||
messages.rowid AS rowid, messages.author, json(messages.content) AS content, messages.sequence
|
||||
FROM
|
||||
messages,
|
||||
json_each(?2) AS following
|
||||
WHERE
|
||||
messages.author = following.value AND
|
||||
messages.content ->> 'type' = 'about' AND
|
||||
messages.rowid > ?6 AND
|
||||
messages.rowid <= ?4
|
||||
)
|
||||
ORDER BY rowid LIMIT ?5
|
||||
`,
|
||||
[
|
||||
JSON.stringify(ids.filter((id) => cache.about[id])),
|
||||
JSON.stringify(ids.filter((id) => !cache.about[id])),
|
||||
cache.last_row_id,
|
||||
max_row_id,
|
||||
k_chunk_size,
|
||||
min_row_id,
|
||||
]
|
||||
);
|
||||
let max_seen;
|
||||
for (let about of abouts) {
|
||||
let content = JSON.parse(about.content);
|
||||
if (content.about === about.author) {
|
||||
delete content.type;
|
||||
delete content.about;
|
||||
cache.about[about.author] = Object.assign(
|
||||
cache.about[about.author] || {},
|
||||
content
|
||||
);
|
||||
}
|
||||
max_seen = about.rowid;
|
||||
}
|
||||
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);
|
||||
if (new_cache !== original_cache) {
|
||||
let start_time = new Date();
|
||||
tfrpc.rpc.databaseSet('about', new_cache).then(function () {
|
||||
console.log('saving about took', (new Date() - start_time) / 1000);
|
||||
});
|
||||
}
|
||||
users = users || {};
|
||||
for (let id of Object.keys(cache.about)) {
|
||||
users[id] = Object.assign(
|
||||
{follow_depth: following[id]?.d},
|
||||
users[id] || {},
|
||||
cache.about[id]
|
||||
);
|
||||
}
|
||||
}
|
||||
cache.last_row_id = max_row_id;
|
||||
let new_cache = JSON.stringify(cache);
|
||||
if (new_cache !== original_cache) {
|
||||
let start_time = new Date();
|
||||
tfrpc.rpc.databaseSet('about', new_cache).then(function () {
|
||||
console.log('saving about took', (new Date() - start_time) / 1000);
|
||||
});
|
||||
}
|
||||
users = users || {};
|
||||
for (let id of Object.keys(cache.about)) {
|
||||
users[id] = Object.assign(
|
||||
{follow_depth: following[id]?.d},
|
||||
users[id] || {},
|
||||
cache.about[id]
|
||||
);
|
||||
if (cache.last_row_id >= max_row_id) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user