Skip to content

Commit

Permalink
Optimize single page load
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Oct 23, 2024
1 parent 354111f commit 24fd500
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/cache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ export function getLastComment(submissionId) {
};
}

export async function getSubmission(index, href, identityFilter) {
export async function getSubmission(index, href, identityFilter, hrefs) {
let submission;
if (index) {
submission = db
Expand Down Expand Up @@ -585,7 +585,13 @@ export async function getSubmission(index, href, identityFilter) {
)
.all(submission.href);

if (identityFilter) {
if (
(identityFilter && !hrefs) ||
(identityFilter &&
hrefs &&
hrefs.length !== 0 &&
hrefs.includes(submission.href))
) {
let validatedUpvoters = [];
// NOTE: When I tried using a map and Promise allSettled to parallelize,
// the ethers component of identityFilter was constantly failing with call
Expand Down
16 changes: 15 additions & 1 deletion src/views/story.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,23 @@ export async function generateStory(index) {
throw new Error("Index wasn't found");
}

const sheetName = "contest";
let result;
try {
result = await curation.getSheet(sheetName);
} catch (err) {
log(`Error getting contest submissions ${err.stack}`);
return [];
}

let submission;
try {
submission = await getSubmission(index, null, identityClassifier);
submission = await getSubmission(
index,
null,
identityClassifier,
result.links,
);
} catch (err) {
log(
`Requested index "${index}" but didn't find because of error "${err.toString()}"`,
Expand Down

0 comments on commit 24fd500

Please sign in to comment.