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