Skip to content

Commit 94e7317

Browse files
authored
fix(trpc): let the hourly MRR refresh collect the run it started (#6931)
refreshSigmaMrr ignored the cache only on its first step, the one that starts a Sigma run. Every poll after that honoured the cache, found the previous 12h entry still valid, and returned it — so the job reported refreshed while the run it had just started was never collected and its pending handle expired. The admin MRR tile only moved when the entry lapsed, up to 12h behind what Sigma had already computed, and each hourly run was burnt for nothing (~24 a day). Every step now ignores the cache; the finished run is returned straight from the pending branch, which is where it always landed.
1 parent c543f1f commit 94e7317

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

packages/trpc/src/router/analytics/business.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,18 +270,19 @@ export async function refreshSigmaMrr({
270270
pollIntervalMs?: number;
271271
} = {}): Promise<MrrResult> {
272272
const startedAt = Date.now();
273-
// Ignore the cache on the first step only. Otherwise a scheduled refresh
274-
// that runs more often than the entry expires would read its own previous
275-
// result and never actually refresh. Subsequent steps must consult the
276-
// cache, since that is where the finished run lands.
273+
// Ignore the cache on every step. The job runs more often than the entry
274+
// expires, so honouring it would hand back the previous result before the
275+
// pending run is ever collected — the tile would then only move when the
276+
// entry lapsed, with a Sigma run burnt every hour for nothing. The finished
277+
// run is returned straight from the pending branch, not via the cache.
277278
let last = await advanceSigmaMrr({ ignoreCache: true });
278279
while (
279280
!last.available &&
280281
last.reason === MRR_COMPUTING_REASON &&
281282
Date.now() - startedAt < timeBudgetMs
282283
) {
283284
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
284-
last = await advanceSigmaMrr();
285+
last = await advanceSigmaMrr({ ignoreCache: true });
285286
}
286287
return last;
287288
}

0 commit comments

Comments
 (0)