ssb: Faster loads by encouraging the right queries with CTEs in fetch_about.
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
This commit is contained in:
parent
b3cedf2baa
commit
f1ced31f69
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"type": "tildefriends-app",
|
"type": "tildefriends-app",
|
||||||
"emoji": "🦀",
|
"emoji": "🦀",
|
||||||
"previous": "&YeFLcHjD39FzsciGDfXuLd0hPzu4Rrp7QlMA7NaUCio=.sha256"
|
"previous": "&RkHUl/WRe0UpvTB2W6cw0f4AeupL/2PEI1pXg5PDXBg=.sha256"
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,7 @@ class TfElement extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const k_account_chunk_size = 4096;
|
||||||
const k_chunk_size = 1024;
|
const k_chunk_size = 1024;
|
||||||
let min_row_id = 0;
|
let min_row_id = 0;
|
||||||
console.log(
|
console.log(
|
||||||
@ -189,54 +190,62 @@ class TfElement extends LitElement {
|
|||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
while (true) {
|
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;
|
let max_seen;
|
||||||
for (let about of abouts) {
|
for (let account_chunk = 0; account_chunk < ids.length; account_chunk += k_account_chunk_size) {
|
||||||
let content = JSON.parse(about.content);
|
let ids_chunk = ids.slice(account_chunk, account_chunk + k_account_chunk_size);
|
||||||
if (content.about === about.author) {
|
let abouts = await tfrpc.rpc.query(
|
||||||
delete content.type;
|
`
|
||||||
delete content.about;
|
WITH
|
||||||
cache.about[about.author] = Object.assign(
|
past AS (
|
||||||
cache.about[about.author] || {},
|
SELECT
|
||||||
content
|
messages.rowid AS rowid, messages.author, json(messages.content) AS content, messages.sequence
|
||||||
);
|
FROM
|
||||||
|
messages
|
||||||
|
WHERE
|
||||||
|
messages.rowid > ?3 AND
|
||||||
|
messages.rowid <= ?4 AND
|
||||||
|
messages.content ->> 'type' = 'about'
|
||||||
|
),
|
||||||
|
current AS (
|
||||||
|
SELECT
|
||||||
|
messages.rowid AS rowid, messages.author, json(messages.content) AS content, messages.sequence
|
||||||
|
FROM
|
||||||
|
messages
|
||||||
|
WHERE
|
||||||
|
messages.rowid > ?6 AND
|
||||||
|
messages.rowid <= ?4 AND
|
||||||
|
messages.content ->> 'type' = 'about'
|
||||||
|
)
|
||||||
|
SELECT * FROM past
|
||||||
|
JOIN json_each(?1) AS following
|
||||||
|
ON past.author = following.value
|
||||||
|
UNION SELECT * FROM current
|
||||||
|
JOIN json_each(?2) AS following
|
||||||
|
ON current.author = following.value
|
||||||
|
ORDER BY rowid LIMIT ?5
|
||||||
|
`,
|
||||||
|
[
|
||||||
|
JSON.stringify(ids_chunk.filter((id) => cache.about[id])),
|
||||||
|
JSON.stringify(ids_chunk.filter((id) => !cache.about[id])),
|
||||||
|
cache.last_row_id,
|
||||||
|
max_row_id,
|
||||||
|
k_chunk_size,
|
||||||
|
min_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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
max_seen = about.rowid;
|
||||||
}
|
}
|
||||||
max_seen = about.rowid;
|
console.log(account_chunk, '/', ids.length, 'accounts');
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
'cache =',
|
'cache =',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user