Oh, votes are slowing everything down. Batch them and simplify.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3648 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-01-20 02:20:40 +00:00
parent 03cf347394
commit 87747c0b6b
6 changed files with 35 additions and 36 deletions

View File

@@ -1,7 +1,7 @@
"use strict";
const k_posts_max = 20;
const k_votes_max = 100;
const k_votes_max = 20;
async function following(db, id) {
var o = await db.get(id + ":following");
@@ -188,7 +188,7 @@ async function getRecentPostIds(db, id, ids, limit) {
async function getVotes(db, id) {
var o = await db.get(id + ":votes");
const k_version = 3;
const k_version = 5;
var votes = [];
var f = o ? JSON.parse(o) : o;
if (!f || f.version != k_version) {
@@ -231,12 +231,7 @@ async function getPosts(db, ids) {
await ssb.sqlStream(
"SELECT rowid, * FROM messages WHERE id IN (" + ids.map(x => "?").join(", ") + ")",
ids,
function(row) {
try {
posts.push(row);
} catch {
}
});
row => posts.push(row));
}
return posts;
}
@@ -278,21 +273,19 @@ async function refresh() {
return root && posts.every(post => post.id != root);
});
return [].concat(posts, await getPosts(db, roots));
}).then(async function(posts) {
posts.forEach(async function(post) {
await app.postMessage({message: post});
});
}).then(function(posts) {
return Promise.all(posts.map(x => app.postMessage({message: x})));
});
f.forEach(async function(id) {
await Promise.all([
getVotes(db, id).then(async function(votes) {
return Promise.all(votes.map(vote => app.postMessage({vote: vote})));
Promise.all(f.map(function(id) {
return Promise.all([
getVotes(db, id).then(function(votes) {
return app.postMessage({votes: votes});
}),
getAbout(db, id).then(async function(user) {
getAbout(db, id).then(function(user) {
return app.postMessage({user: {user: id, about: user}});
}),
]);
});
}));
}),
sendUser(db, whoami),
]);