Skip to content

Commit

Permalink
Cache contests for a small duration during magic (#50)
Browse files Browse the repository at this point in the history
Previously it was not cached at all. Handles change so we don't want to cache for too long.
  • Loading branch information
meooow25 authored Jan 1, 2023
1 parent 6288173 commit afa2f1b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions carrot/src/background/cache/contests-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Contest.IsRated = {
LIKELY: 'LIKELY',
};

const MAGIC_CACHE_DURATION = 5 * 60 * 1000; // 5 mins
const RATING_PENDING_MAX_DAYS = 3;

function isOldContest(contest) {
Expand Down Expand Up @@ -82,15 +83,22 @@ export class ContestsComplete {

// If the contest is finished, the contest data doesn't change so cache it.
// The exception is during new year's magic, when people change handles and handles on the
// ranklist can become outdated.
// ranklist can become outdated. So cache it only for a small duration.
// TODO: New users can also change handles upto a week(?) after joining. Is this a big enough
// issue to stop caching completely?
if (isFinished && !isMagicOn()) {
if (isFinished) {
this.contests.set(contestId, c);
this.contestIds.push(contestId);
if (this.contestIds.length > MAX_FINISHED_CONTESTS_TO_CACHE) {
this.contests.delete(this.contestIds.shift());
}
if (isMagicOn()) {
setTimeout(() => {
this.contests.delete(contestId);
this.contestIds = this.contestIds.filter((cid) => cid !== contestId);
},
MAGIC_CACHE_DURATION);
}
}

return c;
Expand Down

0 comments on commit afa2f1b

Please sign in to comment.