Skip to content

Commit

Permalink
Refetch partial active polls if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
hernandoagf committed Jul 18, 2023
1 parent ba5724d commit 7fb59c5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions modules/polling/api/fetchPolls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,22 @@ export async function refetchPolls(
export async function getActivePollIds(network: SupportedNetworks): Promise<number[]> {
const { valid: cachedPollsAreValid, hash: githubHash } = await checkCachedPollsValidity(network);

let partialActivePolls: PartialActivePoll[] = [];
let partialActivePolls: PartialActivePoll[] | undefined;

if (cachedPollsAreValid) {
const cachedPartialActivePolls = await cacheGet(partialActivePollsCacheKey, network, ONE_WEEK_IN_MS);
if (cachedPartialActivePolls) {
partialActivePolls = JSON.parse(cachedPartialActivePolls);
}
} else {
}

if (!partialActivePolls) {
const { partialActivePolls: newPartialActivePolls } = await refetchPolls(network, githubHash as string);
partialActivePolls = newPartialActivePolls;
}

const activePollIds = partialActivePolls
.filter(poll => new Date(poll.endDate) > new Date())
.map(poll => poll.pollId);
const activePollIds =
partialActivePolls?.filter(poll => new Date(poll.endDate) > new Date()).map(poll => poll.pollId) || [];

return activePollIds;
}
Expand Down

0 comments on commit 7fb59c5

Please sign in to comment.