Skip to content

Commit

Permalink
Re-add upvoteID caching to reconcile mode
Browse files Browse the repository at this point in the history
upvoteID needs to go through all messages and comments before it can
actually guard the database from duplicate upvotes.

However, an earlier fix has allowed it to run reconcile mode where only
the last week's upvotes and comments are cached, not guarding against
duplicate upvotes for nodes which run reconcile mode
  • Loading branch information
TimDaub committed Oct 18, 2024
1 parent 345e0d4 commit e52dfed
Showing 1 changed file with 56 additions and 57 deletions.
113 changes: 56 additions & 57 deletions src/launch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,65 +61,64 @@ await subscribe(
trie,
);

if (!reconcileMode) {
// NOTE: This request queries all messages in the database to enable caching
// when calling ecrecover on messages' signatures
const from = null;
const amount = null;

const oneWeekAgo = subWeeks(new Date(), 1).getTime() / 1000;
let startDatetime = oneWeekAgo;
if (productionMode) {
startDatetime = null;
}

const parser = JSON.parse;
const accounts = await registry.accounts();
const delegations = await registry.delegations();
const href = null;

let upvotes, comments;
await Promise.allSettled([
store
.posts(
trie,
from,
amount,
parser,
startDatetime,
accounts,
delegations,
href,
"amplify",
)
.then((result) => (upvotes = result))
.catch((error) => console.error("Amplify posts error:", error)),
store
.posts(
trie,
from,
amount,
parser,
startDatetime,
accounts,
delegations,
href,
"comment",
)
.then((result) => (comments = result))
.catch((error) => console.error("Comment posts error:", error)),
]);

// NOTE: This request queries all messages in the database to enable caching
// when calling ecrecover on messages' signatures.
//
// NOTE: Yes, this does influence the startup duration of a node as it extracts
// and re-validates all messages from the DB. However, the store.cache function
// is necessary to be run as it generates the markers that prevent double
// upvoting from happening.
const from = null;
const amount = null;
const startDatetime = null;
const parser = JSON.parse;
const accounts = await registry.accounts();
const delegations = await registry.delegations();
const href = null;

let upvotes, comments;
await Promise.allSettled([
store
.posts(
trie,
from,
amount,
parser,
startDatetime,
accounts,
delegations,
href,
"amplify",
)
.then((result) => (upvotes = result))
.catch((error) => console.error("Amplify posts error:", error)),
store
.cache(upvotes, comments)
.then(() => log("store cached"))
.catch((err) => {
log(
`launch: An irrecoverable error during upvote caching occurred. "${err.toString()}`,
);
exit(1);
});
.posts(
trie,
from,
amount,
parser,
startDatetime,
accounts,
delegations,
href,
"comment",
)
.then((result) => (comments = result))
.catch((error) => console.error("Comment posts error:", error)),
]);

store
.cache(upvotes, comments)
.then(() => log("store cached"))
.catch((err) => {
log(
`launch: An irrecoverable error during upvote caching occurred. "${err.toString()}`,
);
exit(1);
});

if (!reconcileMode) {
const urls = await moderation.getFeeds();
Promise.all([feeds.recompute(urls), newest.recompute(trie)]).then(() =>
log("Feeds computed"),
Expand Down

0 comments on commit e52dfed

Please sign in to comment.