@devries-cameron20 / t3code Mirror · read-only / commits / ccca13dcf4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 08:00 UTC

perf(server): expanding a wide ignored folder no longer classifies every child (#20062)

Co-authored-by: Aaron Queen <bompus@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 15, 2026 at 20:07 UTC ccca13dcf4a70a45954a3a1a6de8306a67ef9a6f
2 files changed +114 -15
apps/server/src/workspace/WorkspaceEntries.test.ts
+70
@@ -134,6 +134,76 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
134 }),
135 );
136
137 + it.effect("labels the children of wide folders exactly as git does for each child", () =>
138 + Effect.gen(function* () {
139 + // Above 1,000 children, listing first asks whether the whole folder is ignored.
140 + const cwd = yield* makeTempDir({ git: true });
141 + const fileSystem = yield* FileSystem.FileSystem;
142 + const path = yield* Path.Path;
143 + const platform = yield* HostProcess.Platform;
144 + yield* writeTextFile(
145 + cwd,
146 + ".gitignore",
147 + "node_modules/\ndist/\n\\[id\\]/\n*.map\nfoo\n!foo/\n",
148 + );
149 + yield* Effect.forEach(
150 + [
151 + "node_modules",
152 + "dist",
153 + "[id]",
154 + "src",
155 + ...(platform !== "win32" ? [":foo"] : []),
156 + ].flatMap((directory) =>
157 + Array.from({ length: 1001 }, (_, index) => `${directory}/pkg-${index}.js`),
158 + ),
159 + (relativePath) => writeTextFile(cwd, relativePath),
160 + { concurrency: 32, discard: true },
161 + );
162 + for (const relativePath of [
163 + "dist/kept.js",
164 + "dist/vendored/index.js",
165 + "i/page.tsx",
166 + "[id]/page.tsx",
167 + "src/bundle.map",
168 + ]) {
169 + yield* writeTextFile(cwd, relativePath);
170 + }
171 + yield* git(cwd, ["add", "-f", "dist/kept.js", "dist/vendored/index.js", "i/page.tsx"]);
172 + if (platform !== "win32") {
173 + yield* fileSystem.symlink(path.join(cwd, "src"), path.join(cwd, "node_modules/link"));
174 + }
175 +
176 + const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
177 + for (const { directoryPath, ignored, except } of [
178 + { directoryPath: "node_modules", ignored: true, except: [] },
179 + // A force-tracked file and a folder holding tracked files stay unignored.
180 + { directoryPath: "dist", ignored: true, except: ["dist/kept.js", "dist/vendored"] },
181 + // git reads `[id]/page.tsx` as a pathspec, which matches the tracked `i/page.tsx`.
182 + { directoryPath: "[id]", ignored: true, except: ["[id]/page.tsx"] },
183 + { directoryPath: "src", ignored: false, except: ["src/bundle.map"] },
184 + ...(platform !== "win32"
185 + ? [
186 + // git refuses to classify paths beyond a symlink, so nothing there is labelled.
187 + { directoryPath: "node_modules/link", ignored: false, except: [] },
188 + // A leading `:` is pathspec magic, so git reads `:foo/pkg-0.js` as `foo/pkg-0.js`,
189 + // which `!foo/` keeps unignored.
190 + { directoryPath: ":foo", ignored: false, except: [] },
191 + ]
192 + : []),
193 + ]) {
194 + const { entries } = yield* workspaceEntries.list({ cwd, directoryPath });
195 + expect(entries.length, directoryPath).toBeGreaterThan(1000);
196 + expect(
197 + entries
198 + .filter((entry) => (entry.ignored === true) !== ignored)
199 + .map((entry) => entry.path)
200 + .toSorted(),
201 + directoryPath,
202 + ).toEqual(except);
203 + }
204 + }),
205 + );
206 +
207 it.effect("lists a host folder and its parent, each from its own root", () =>
208 // Folder links outside the workspace browse by passing the host folder as
209 // `cwd`; walking up passes the parent. Each stays bounded by its own root.
apps/server/src/workspace/WorkspaceEntries.ts
+44 -15
@@ -106,6 +106,9 @@ export class WorkspaceEntries extends Context.Service<
106 }
107 >()("t3/workspace/WorkspaceEntries") {}
108
109 +/** Paths sent to one `git check-ignore` call when labelling a folder's children. */
110 +const IGNORE_CHECK_CHUNK_SIZE = 1000;
111 +
112 const resolveBrowseTarget = Effect.fn("WorkspaceEntries.resolveBrowseTarget")(function* (
113 input: FilesystemBrowseInput,
114 path: Path.Path,
@@ -291,7 +294,7 @@ export const make = Effect.gen(function* () {
294 relativePath: directoryPath,
295 })
296 .pipe(Effect.mapError(toError));
294 - const entries = yield* Effect.tryPromise({
297 + const { entries, throughSymlink } = yield* Effect.tryPromise({
298 try: async () => {
299 const root = await NodeFSP.realpath(normalizedCwd);
300 const directory = await NodeFSP.realpath(target.absolutePath);
@@ -306,35 +309,61 @@ export const make = Effect.gen(function* () {
309 throw new Error("Directory must be inside the workspace and outside .git.");
310 }
311 const children = await NodeFSP.readdir(directory, { withFileTypes: true });
309 - return children.flatMap((child): ProjectEntry[] => {
310 - if (child.name === ".git" || (!child.isDirectory() && !child.isFile())) return [];
311 - return [
312 - {
313 - path: target.relativePath ? `${target.relativePath}/${child.name}` : child.name,
314 - kind: child.isDirectory() ? "directory" : "file",
315 - },
316 - ];
317 - });
312 + return {
313 + entries: children.flatMap((child): ProjectEntry[] => {
314 + if (child.name === ".git" || (!child.isDirectory() && !child.isFile())) return [];
315 + return [
316 + {
317 + path: target.relativePath ? `${target.relativePath}/${child.name}` : child.name,
318 + kind: child.isDirectory() ? "directory" : "file",
319 + },
320 + ];
321 + }),
322 + // Git refuses to classify paths beyond a symbolic link.
323 + throughSymlink: relative !== target.relativePath.split("/").join(path.sep),
324 + };
325 },
326 catch: toError,
327 });
328 // Use stdin so large directories cannot exceed the command-line argument limit.
329 // Ignore classification is optional in non-git workspaces or when git is unavailable.
323 - const ignored = new Set<string>();
324 - for (let offset = 0; offset < entries.length; offset += 1000) {
325 - const chunk = entries.slice(offset, offset + 1000);
326 - const result = yield* vcsProcess
330 + const checkIgnore = (paths: ReadonlyArray<string>) =>
331 + vcsProcess
332 .run({
333 operation: "WorkspaceEntries.list",
334 command: "git",
335 args: ["-c", "core.fsmonitor=false", "check-ignore", "-z", "--stdin"],
336 cwd: normalizedCwd,
332 - stdin: `${chunk.map((entry) => entry.path).join("\0")}\0`,
337 + stdin: `${paths.join("\0")}\0`,
338 allowNonZeroExit: true,
339 timeoutMs: 10_000,
340 maxOutputBytes: 16 * 1024 * 1024,
341 })
342 .pipe(Effect.orElseSucceed(() => undefined));
343 + // Git consults the index for every path it classifies, which costs hundreds of
344 + // milliseconds for a `node_modules`-sized folder. Asking about the folder itself answers
345 + // for every child: `check-ignore` exits 0 only when the folder is ignored and nothing
346 + // under it is tracked, and an ignored folder hides all of its children. Git reads paths as
347 + // pathspecs, so a folder whose path has magic (`:foo`) or glob (`[id]`) characters, or
348 + // one reached through a symlink, can get a different answer per child and still asks git
349 + // about each.
350 + if (
351 + entries.length > IGNORE_CHECK_CHUNK_SIZE &&
352 + target.relativePath !== "" &&
353 + !throughSymlink &&
354 + !/^:|[*?[\\]/.test(target.relativePath) &&
355 + (yield* checkIgnore([target.relativePath]))?.exitCode === 0
356 + ) {
357 + return {
358 + entries: entries.map((entry) => ({ ...entry, ignored: true })),
359 + truncated: false,
360 + };
361 + }
362 + const ignored = new Set<string>();
363 + for (let offset = 0; offset < entries.length; offset += IGNORE_CHECK_CHUNK_SIZE) {
364 + const result = yield* checkIgnore(
365 + entries.slice(offset, offset + IGNORE_CHECK_CHUNK_SIZE).map((entry) => entry.path),
366 + );
367 if (!result || (result.exitCode !== 0 && result.exitCode !== 1)) break;
368 for (const ignoredPath of result.stdout.split("\0")) ignored.add(ignoredPath);
369 }