Skip to content

Commit

Permalink
Parallelize upvote and comment retrieval on launch
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Jul 5, 2024
1 parent e93386f commit bac6d23
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/launch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,36 @@ const parser = JSON.parse;
const accounts = await registry.accounts();
const delegations = await registry.delegations();
const href = null;
const upvotes = await store.posts(
trie,
from,
amount,
parser,
startDatetime,
accounts,
delegations,
href,
"amplify",
);
const comments = await store.posts(
trie,
from,
amount,
parser,
startDatetime,
accounts,
delegations,
href,
"comment",
);

let upvotes, comments;
await Promise.allSettled([
(async () => {
upvotes = await store.posts(
trie,
from,
amount,
parser,
startDatetime,
accounts,
delegations,
href,
"amplify",
);
})(),
(async () => {
comments = await store.posts(
trie,
from,
amount,
parser,
startDatetime,
accounts,
delegations,
href,
"comment",
);
})(),
]);

const alreadySetup = cache.initialize();
if (!alreadySetup) {
Expand All @@ -93,6 +101,7 @@ try {

const urls = await moderation.getFeeds();
await feeds.recompute(urls);
// TODO: Unclear if this is still necessary
setInterval(async () => {
await feeds.recompute(urls);
await newest.recompute(trie);
Expand Down

0 comments on commit bac6d23

Please sign in to comment.