perf(server): reduce branch PR discovery cache churn #26036
Closedagentic-jarmo(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/26036/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -2656,3 +2661,20 @@2661+ function* (cwd, options) {26562662 yield* invalidateLocalStatusResultCache(cwd);26572663 yield* invalidateRemoteStatusResultCache(cwd);2658- yield* bumpPrLookupEpoch(cwd);2664+ const cacheCwd = yield* normalizeStatusCacheKey(cwd);2665+ const branch = options?.currentBranchOnly2666+ ? yield* gitCore.resolveBranchName(cacheCwd, "HEAD").pipe(Effect.orElseSucceed(() => null))2667+ : null;2668+ if (branch !== null) {2669+ // Refresh the visible branch without turning unrelated background PR2670+ // lookups into cold reads on every client wake or status refresh.2671+ const prefix = [cacheCwd, branch, ""].join("\u0000");2672+ const keys = Array.from(yield* Cache.keys(prLookupCache));2673+ yield* Effect.forEach(2674+ keys.filter((key) => key.startsWith(prefix)),2675+ (key) => Cache.invalidate(prLookupCache, key),2676+ );2677+ } else {2678+ yield* bumpPrLookupEpoch(cwd);2679+ }2680+ gitStateEpochByCwd.set(cacheCwd, gitStateEpoch(cacheCwd) + 1);
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
- @@ -2403,10 +2413,19 @@24032413 }24042414 prLookupGitStateByKey.set(entryKey, { readAtMs, value });24052415 return value;24062416 });2407- const forgetPrLookupGitState = (cwd: string) =>2417+ const forgetPrLookupGitState = (cwd: string, branch?: string) =>24082418 normalizeStatusCacheKey(cwd).pipe(24092419 Effect.map((cacheCwd) => {24102420 const prefix = `${cacheCwd}\u0000`;24112421 for (const key of prLookupGitStateByKey.keys()) {2412- if (key.startsWith(prefix)) prLookupGitStateByKey.delete(key);2422+ if (!key.startsWith(prefix)) continue;2423+ const metadataKey = key.slice(prefix.length);2424+ // Fetch can change shared remote state, but not other branches' local refs or config.2425+ const unrelatedBranch =2426+ branch !== undefined &&2427+ ((metadataKey.startsWith("branchRef\u0000") &&2428+ metadataKey !== `branchRef\u0000${branch}`) ||2429+ (metadataKey.startsWith("config\u0000branch.") &&2430+ metadataKey !== `config\u0000branch.${branch}.remote`));2431+ if (!unrelatedBranch) prLookupGitStateByKey.delete(key);
github-actions[bot](GitHub profile, opens in a new tab) removed labelsneeds-rebase
Sign in to join this conversation.

macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes