Skip to content

Commit bb76491

Browse files
fix(server): key status caches by gitCommonDir instead of cwd
Cache factories already use gitCommonDir as their key, but the Cache.get call site in readStatusDetailsLocal was passing a normalized cwd path. This meant every status refresh missed the cache (different key) and re-fetched the git subprocesses. Worse, sibling worktree mutations invalidated by gitCommonDir never cleared the cwd-keyed entry. Now resolve repositoryPaths early in readStatusDetailsLocal and pass gitCommonDir as the cache key, matching what the factories expect and what invalidateStatusStaticCaches already uses.
1 parent a3a4676 commit bb76491

1 file changed

Lines changed: 49 additions & 7 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,19 +1122,55 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
11221122
};
11231123

11241124
const defaultBranchCache = yield* Cache.makeWith(
1125-
(cwd: string) => resolveDefaultBranchName(cwd, "origin"),
1125+
(gitCommonDir: string) =>
1126+
Effect.gen(function* () {
1127+
const path = yield* Path.Path;
1128+
const fetchCwd =
1129+
path.basename(gitCommonDir) === ".git" ? path.dirname(gitCommonDir) : gitCommonDir;
1130+
return yield* executeGit(
1131+
"GitVcsDriver.statusDetails.defaultBranch",
1132+
fetchCwd,
1133+
["--git-dir", gitCommonDir, "symbolic-ref", "refs/remotes/origin/HEAD"],
1134+
{ allowNonZeroExit: true },
1135+
).pipe(
1136+
Effect.map((result) => {
1137+
if (result.exitCode !== 0) return null;
1138+
return parseDefaultBranchFromRemoteHeadRef(result.stdout, "origin");
1139+
}),
1140+
);
1141+
}),
11261142
{
11271143
capacity: 2_048,
11281144
timeToLive: () => STATUS_DEFAULT_BRANCH_CACHE_TTL,
11291145
},
11301146
);
1131-
const originExistsCache = yield* Cache.makeWith((cwd: string) => originRemoteExists(cwd), {
1132-
capacity: 2_048,
1133-
timeToLive: () => STATUS_ORIGIN_EXISTS_CACHE_TTL,
1134-
});
1147+
const originExistsCache = yield* Cache.makeWith(
1148+
(gitCommonDir: string) =>
1149+
Effect.gen(function* () {
1150+
const path = yield* Path.Path;
1151+
const fetchCwd =
1152+
path.basename(gitCommonDir) === ".git" ? path.dirname(gitCommonDir) : gitCommonDir;
1153+
return yield* executeGit(
1154+
"GitVcsDriver.statusDetails.originExists",
1155+
fetchCwd,
1156+
["--git-dir", gitCommonDir, "remote", "get-url", "origin"],
1157+
{ allowNonZeroExit: true },
1158+
).pipe(Effect.map((result) => result.exitCode === 0));
1159+
}),
1160+
{
1161+
capacity: 2_048,
1162+
timeToLive: () => STATUS_ORIGIN_EXISTS_CACHE_TTL,
1163+
},
1164+
);
11351165
const invalidateStatusStaticCaches = (cwd: string) =>
11361166
Effect.gen(function* () {
1137-
const cacheKey = normalizeRepositoryPathsCacheKey(cwd);
1167+
const repositoryPaths = yield* resolveRepositoryPaths(cwd).pipe(
1168+
Effect.catchTags({
1169+
GitCommandError: (error) =>
1170+
isMissingGitCwdError(error) ? Effect.succeed(null) : Effect.fail(error),
1171+
}),
1172+
);
1173+
const cacheKey = repositoryPaths?.gitCommonDir ?? cwd;
11381174
yield* Cache.invalidate(defaultBranchCache, cacheKey);
11391175
yield* Cache.invalidate(originExistsCache, cacheKey);
11401176
});
@@ -1537,7 +1573,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
15371573
});
15381574
}
15391575

1540-
const statusCacheKey = normalizeRepositoryPathsCacheKey(cwd);
1576+
const repositoryPaths = yield* resolveRepositoryPaths(cwd).pipe(
1577+
Effect.catchTags({
1578+
GitCommandError: (error) =>
1579+
isMissingGitCwdError(error) ? Effect.succeed(null) : Effect.fail(error),
1580+
}),
1581+
);
1582+
const statusCacheKey = repositoryPaths?.gitCommonDir ?? normalizeRepositoryPathsCacheKey(cwd);
15411583
const [numstatStdout, defaultBranch, hasPrimaryRemote] = yield* Effect.all(
15421584
[
15431585
executeGitWithStableDiagnostics(

0 commit comments

Comments
 (0)