Skip to content

Commit f3f2bf0

Browse files
committed
fix(server): pull request checks expire from when they were observed
1 parent ce47834 commit f3f2bf0

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,20 @@ export const make = Effect.gen(function* () {
29802980
},
29812981
{
29822982
capacity: DETAIL_CACHE_CAPACITY,
2983-
timeToLive: (exit) => (Exit.isSuccess(exit) ? CHECKS_CACHE_TTL : Duration.zero),
2983+
// Expire from the read's start so checks seeded from a slow detail read keep their age.
2984+
timeToLive: (exit) =>
2985+
!Exit.isSuccess(exit)
2986+
? Duration.zero
2987+
: exit.value === null
2988+
? CHECKS_CACHE_TTL
2989+
: Duration.millis(
2990+
Math.max(
2991+
0,
2992+
exit.value.observedAt +
2993+
Duration.toMillis(CHECKS_CACHE_TTL) -
2994+
clock.currentTimeMillisUnsafe(),
2995+
),
2996+
),
29842997
},
29852998
);
29862999

@@ -3014,12 +3027,10 @@ export const make = Effect.gen(function* () {
30143027
return detailUncached(refOfCacheKey(key)).pipe(
30153028
Effect.tap(
30163029
Effect.fn("PullRequestService.recordDetailStats")(function* (value: PullRequestDetail) {
3017-
// GitHub detail includes the same checks; seed only fresh reads at their shorter TTL.
3018-
const now = yield* Clock.currentTimeMillis;
3030+
// GitHub detail includes the same checks; the checks TTL counts from their observation.
30193031
if (
30203032
value.provider === "github" &&
30213033
value.observedAt !== undefined &&
3022-
now - value.observedAt < Duration.toMillis(CHECKS_CACHE_TTL) &&
30233034
!(yield* Cache.has(checksCache, key))
30243035
) {
30253036
yield* Cache.set(checksCache, key, {
@@ -3037,7 +3048,7 @@ export const make = Effect.gen(function* () {
30373048
additions: value.additions,
30383049
deletions: value.deletions,
30393050
},
3040-
now,
3051+
yield* Clock.currentTimeMillis,
30413052
);
30423053
}),
30433054
),

0 commit comments

Comments
 (0)