ssb: Now add back the about cache, and load times are getting good.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 31m43s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 31m43s
This commit is contained in:
parent
58c3e6c2ab
commit
8e3bc9d700
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"type": "tildefriends-app",
|
"type": "tildefriends-app",
|
||||||
"emoji": "🦀",
|
"emoji": "🦀",
|
||||||
"previous": "&NajVQD/6DKISEDlnyAVYh3NPO/vxMN7ksNZy3FwI378=.sha256"
|
"previous": "&VQsPosjAfr008a6UMb8vKmKxE/WS4DRKEspJL8Lewjw=.sha256"
|
||||||
}
|
}
|
||||||
|
@ -152,39 +152,83 @@ class TfElement extends LitElement {
|
|||||||
|
|
||||||
async fetch_about(following, users) {
|
async fetch_about(following, users) {
|
||||||
let ids = Object.keys(following).sort();
|
let ids = Object.keys(following).sort();
|
||||||
console.log('loading about for', ids.length, 'accounts');
|
const k_cache_version = 2;
|
||||||
try {
|
let cache = await tfrpc.rpc.databaseGet('about');
|
||||||
let rows = await tfrpc.rpc.query(
|
let original_cache = cache;
|
||||||
`
|
cache = cache ? JSON.parse(cache) : {};
|
||||||
SELECT all_abouts.author, json(json_group_object(all_abouts.key, all_abouts.value)) AS about
|
if (cache.version !== k_cache_version) {
|
||||||
FROM (
|
cache = {
|
||||||
SELECT
|
version: k_cache_version,
|
||||||
messages.author,
|
about: {},
|
||||||
fields.key,
|
};
|
||||||
RANK() OVER (PARTITION BY messages.author, fields.key ORDER BY messages.sequence DESC) AS rank,
|
}
|
||||||
fields.value
|
|
||||||
FROM messages JOIN json_each(messages.content) AS fields
|
for (let id of Object.keys(cache.about)) {
|
||||||
WHERE
|
if (ids.indexOf(id) == -1) {
|
||||||
messages.content ->> '$.type' = 'about' AND
|
delete cache.about[id];
|
||||||
messages.content ->> '$.about' = messages.author AND
|
} else {
|
||||||
NOT fields.key IN ('about', 'type')) all_abouts
|
users[id] = Object.assign(
|
||||||
JOIN json_each(?) AS following ON all_abouts.author = following.value
|
users[id] || {},
|
||||||
WHERE rank = 1
|
cache.about[id]
|
||||||
GROUP BY all_abouts.author
|
|
||||||
`,
|
|
||||||
[JSON.stringify(ids)]
|
|
||||||
);
|
|
||||||
users = users || {};
|
|
||||||
for (let row of rows) {
|
|
||||||
users[row.author] = Object.assign(
|
|
||||||
users[row.author] || {},
|
|
||||||
JSON.parse(row.about)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
console.log('updated users');
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ids_out_of_date = ids.filter(x => cache.about[x]?.seq === undefined || (users[x]?.seq && users[x]?.seq > cache.about[x].seq));
|
||||||
|
|
||||||
|
console.log('loading about for', ids.length, 'accounts', ids_out_of_date.length, 'out of date');
|
||||||
|
if (ids_out_of_date.length) {
|
||||||
|
try {
|
||||||
|
let rows = await tfrpc.rpc.query(
|
||||||
|
`
|
||||||
|
SELECT all_abouts.author, json(json_group_object(all_abouts.key, all_abouts.value)) AS about
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
messages.author,
|
||||||
|
fields.key,
|
||||||
|
RANK() OVER (PARTITION BY messages.author, fields.key ORDER BY messages.sequence DESC) AS rank,
|
||||||
|
fields.value
|
||||||
|
FROM messages JOIN json_each(messages.content) AS fields
|
||||||
|
WHERE
|
||||||
|
messages.content ->> '$.type' = 'about' AND
|
||||||
|
messages.content ->> '$.about' = messages.author AND
|
||||||
|
NOT fields.key IN ('about', 'type')) all_abouts
|
||||||
|
JOIN json_each(?) AS following ON all_abouts.author = following.value
|
||||||
|
WHERE rank = 1
|
||||||
|
GROUP BY all_abouts.author
|
||||||
|
`,
|
||||||
|
[JSON.stringify(ids_out_of_date)]
|
||||||
|
);
|
||||||
|
users = users || {};
|
||||||
|
for (let row of rows) {
|
||||||
|
users[row.author] = Object.assign(
|
||||||
|
users[row.author] || {},
|
||||||
|
JSON.parse(row.about)
|
||||||
|
);
|
||||||
|
cache.about[row.author] = Object.assign(
|
||||||
|
{seq: users[row.author].seq},
|
||||||
|
JSON.parse(row.about)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let id of ids_out_of_date) {
|
||||||
|
if (!cache.about[id]?.seq) {
|
||||||
|
cache.about[id] = {seq: users[id]?.seq ?? 0};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return Object.assign({}, users);
|
return Object.assign({}, users);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,7 +409,7 @@ class TfElement extends LitElement {
|
|||||||
for (let row of info) {
|
for (let row of info) {
|
||||||
users[row.author] = Object.assign(
|
users[row.author] = Object.assign(
|
||||||
{
|
{
|
||||||
seq: row.max_seq,
|
seq: row.max_sequence,
|
||||||
ts: row.max_ts,
|
ts: row.max_ts,
|
||||||
},
|
},
|
||||||
users[row.author]
|
users[row.author]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user