Sped up some follower/following UI. But ultimately followed more people and made everything else slower.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3720 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-12-29 21:00:03 +00:00
parent f7974d2cef
commit 12010a84a3
5 changed files with 64 additions and 34 deletions

View File

@@ -151,6 +151,7 @@ function fnv32a(value)
async function getRecentPostIds(db, id, ids, limit) {
const k_version = 9;
const k_batch_max = 8;
var o = await db.get(id + ':recent_posts');
var recent = [];
var f = o ? JSON.parse(o) : o;
@@ -158,27 +159,38 @@ async function getRecentPostIds(db, id, ids, limit) {
if (!f || f.version != k_version || f.ids_hash != ids_hash) {
f = {recent: [], rowid: 0, version: k_version, ids_hash: ids_hash};
}
var row_id_max = 0;
await ssb.sqlStream(
"SELECT "+
" rowid, "+
" id, "+
" timestamp "+
"FROM messages "+
"WHERE "+
" rowid > ? AND "+
" author IN (" + ids.map(x => '?').join(", ") + ") AND "+
" json_extract(content, '$.type') IN ('post', 'tildefriends-app') "+
"UNION SELECT MAX(rowid) as rowid, NULL, NULL FROM messages "+
"ORDER BY timestamp DESC LIMIT ?",
[].concat([f.rowid], ids, [limit + 1]),
"SELECT MAX(rowid) as rowid FROM messages ORDER BY timestamp DESC LIMIT ?",
[],
function(row) {
if (row.id) {
recent.push(row.id);
}
if (row.rowid) {
f.rowid = row.rowid;
}
row_id_max = row.rowid;
});
for (var i = 0; i < ids.length; i += k_batch_max) {
var ids_batch = ids.slice(i, Math.min(i + k_batch_max, ids.length));
await ssb.sqlStream(
"SELECT "+
" rowid, "+
" id, "+
" timestamp "+
"FROM messages "+
"WHERE "+
" rowid > ? AND "+
" rowid <= ? AND "+
" author IN (" + ids_batch.map(x => '?').join(", ") + ") AND "+
" json_extract(content, '$.type') IN ('post', 'tildefriends-app') "+
"ORDER BY timestamp DESC LIMIT ?",
[].concat([f.rowid, row_id_max], ids_batch, [limit]),
function(row) {
if (row.id) {
recent.push(row.id);
}
if (row.rowid) {
f.rowid = Math.max(row.rowid, f.rowid);
}
});
}
f.recent.sort((x, y) => x.timestamp - y.timestamp);
f.recent = [].concat(recent, f.recent).slice(0, limit);
var j = JSON.stringify(f);
if (o != j) {