Skip to content

Commit c9211b6

Browse files
fix(server): favicon lookups for a missing project folder are cached (pingdotgg#34905)
1 parent 2e18418 commit c9211b6

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎apps/server/src/project/ProjectFaviconResolver.test.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const writeTextFile = Effect.fn("writeTextFile")(function* (
4343

4444
const makeResolverWithFileSystem = (fileSystem: FileSystem.FileSystem) =>
4545
ProjectFaviconResolver.make.pipe(
46-
Effect.provide([WorkspacePaths.layer, T3ProjectFileLoader.layer]),
46+
Effect.provide([Layer.fresh(WorkspacePaths.layer), T3ProjectFileLoader.layer]),
4747
Effect.provideService(FileSystem.FileSystem, fileSystem),
4848
);
4949

@@ -81,6 +81,28 @@ it.layer(layerTest)("ProjectFaviconResolverLive", (it) => {
8181
}).pipe(Effect.provide(TestClock.layer())),
8282
);
8383

84+
it.effect("looks up a missing workspace root once within the negative cache window", () =>
85+
Effect.gen(function* () {
86+
const fileSystem = yield* FileSystem.FileSystem;
87+
const path = yield* Path.Path;
88+
const cwd = path.join(yield* makeTempDir, "deleted-project");
89+
let rootStats = 0;
90+
const resolver = yield* makeResolverWithFileSystem(
91+
FileSystem.FileSystem.of({
92+
...fileSystem,
93+
stat: (filePath) => {
94+
if (filePath === cwd) rootStats += 1;
95+
return fileSystem.stat(filePath);
96+
},
97+
}),
98+
);
99+
100+
yield* Effect.exit(resolver.resolvePath(cwd));
101+
yield* Effect.exit(resolver.resolvePath(cwd));
102+
expect(rootStats).toBe(1);
103+
}),
104+
);
105+
84106
it.effect("prefers a t3.json iconPath over well-known files", () =>
85107
Effect.gen(function* () {
86108
const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver;

‎apps/server/src/project/ProjectFaviconResolver.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Cache from "effect/Cache";
2+
import * as Cause from "effect/Cause";
23
import * as Context from "effect/Context";
34
import * as Duration from "effect/Duration";
45
import * as Effect from "effect/Effect";
@@ -304,7 +305,10 @@ export const make = Effect.gen(function* () {
304305
timeToLive: Exit.match({
305306
onSuccess: (value: string | null) =>
306307
value === null ? FAVICON_NEGATIVE_CACHE_TTL : FAVICON_POSITIVE_CACHE_TTL,
307-
onFailure: () => Duration.zero,
308+
onFailure: (cause) =>
309+
Option.exists(Cause.findErrorOption(cause), isMissingWorkspaceRoot)
310+
? FAVICON_NEGATIVE_CACHE_TTL
311+
: Duration.zero,
308312
}),
309313
},
310314
);

0 commit comments

Comments
 (0)