Skip to content

Commit 3409651

Browse files
chore(mobile): name the two project favicon caches by their job (#13160)
1 parent ec28eef commit 3409651

8 files changed

Lines changed: 31 additions & 15 deletions

‎apps/mobile/src/components/ProjectFavicon.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
hasLoadedProjectFavicon,
1919
markProjectFaviconFailed,
2020
markProjectFaviconLoaded,
21-
} from "./projectFaviconCache";
21+
} from "../lib/projectFaviconRequests";
2222

2323
const EMPTY_FAVICON_URL = Atom.make<string | null>(null);
2424

‎apps/mobile/src/connection/environment-cache-store.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import * as Option from "effect/Option";
1515
import * as Schema from "effect/Schema";
1616

1717
import * as MobileDatabase from "../persistence/mobile-database";
18-
import { attachProjectFaviconDatabase, projectFaviconCache } from "../lib/projectFaviconCache";
18+
import {
19+
attachProjectFaviconDatabase,
20+
projectFaviconDatabaseCache,
21+
} from "../lib/projectFaviconDatabaseCache";
1922

2023
const SHELL_SNAPSHOT_CACHE_SCHEMA_VERSION = 1;
2124
// v3 adds windowed (paginated) snapshots carrying `page` metadata; the bump
@@ -130,7 +133,7 @@ export const make = Effect.fn("MobileEnvironmentCacheStore.make")(function* () {
130133
decode: decodeStoredShellSnapshot,
131134
select: (stored) =>
132135
stored.environmentId === environmentId ? Option.some(stored.snapshot) : Option.none(),
133-
}).pipe(Effect.tap(() => Effect.promise(() => projectFaviconCache.hydrate()))),
136+
}).pipe(Effect.tap(() => Effect.promise(() => projectFaviconDatabaseCache.hydrate()))),
134137
),
135138
saveShell: Effect.fn("MobileEnvironmentCache.saveShell")(function* (environmentId, snapshot) {
136139
const payload = yield* encodeStoredShellSnapshot({
@@ -241,7 +244,7 @@ export const make = Effect.fn("MobileEnvironmentCacheStore.make")(function* () {
241244
.pipe(Effect.mapError(mapDatabaseError("clear-vcs-refs"))),
242245
),
243246
clear: Effect.fn("MobileEnvironmentCache.clear")((environmentId) =>
244-
Effect.promise(() => projectFaviconCache.clearEnvironment(environmentId)).pipe(
247+
Effect.promise(() => projectFaviconDatabaseCache.clearEnvironment(environmentId)).pipe(
245248
Effect.andThen(database.clearEnvironmentCache(environmentId)),
246249
Effect.mapError(mapDatabaseError("clear-environment")),
247250
),

apps/mobile/src/lib/projectFaviconCache.test.ts renamed to apps/mobile/src/lib/projectFaviconDatabaseCache.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ vi.mock("expo-file-system", () => ({
2727
},
2828
}));
2929

30-
import { downscaleProjectFavicon } from "./projectFaviconCache";
30+
import { downscaleProjectFavicon } from "./projectFaviconDatabaseCache";
3131

3232
const png = "iVBORw0KGgoAAAAA";
3333
const image = { url: "https://remote/icon.png" };

apps/mobile/src/lib/projectFaviconCache.ts renamed to apps/mobile/src/lib/projectFaviconDatabaseCache.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
createProjectFaviconCache,
2+
createProjectFaviconCache as createSharedProjectFaviconCache,
33
createProjectFaviconImageLoader,
44
PROJECT_FAVICON_MAX_DATA_URL_LENGTH,
55
PROJECT_FAVICON_THUMBNAIL_SIZE,
@@ -78,8 +78,13 @@ export async function downscaleProjectFavicon(
7878
throw new Error("Project icon thumbnail exceeds the cache limit.");
7979
}
8080

81-
/** Rows live in `client_cache` so Settings → Client storage counts and clears them. */
82-
export const projectFaviconCache = createProjectFaviconCache({
81+
/**
82+
* The database-backed project favicon cache. Named apart from the shared
83+
* `createProjectFaviconCache` factory it calls and from the in-flight request
84+
* registry in `projectFaviconRequests`. Rows live in `client_cache` so
85+
* Settings → Client storage counts and clears them.
86+
*/
87+
export const projectFaviconDatabaseCache = createSharedProjectFaviconCache({
8388
storage: {
8489
list: () =>
8590
runDatabase((database) =>

apps/mobile/src/components/projectFaviconCache.test.ts renamed to apps/mobile/src/lib/projectFaviconRequests.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
hasLoadedProjectFavicon,
77
markProjectFaviconFailed,
88
markProjectFaviconLoaded,
9-
} from "./projectFaviconCache";
9+
} from "./projectFaviconRequests";
1010

11-
describe("project favicon cache", () => {
11+
describe("project favicon requests", () => {
1212
it("ignores callbacks from a superseded URL", () => {
1313
const cacheKey = "environment-1:/workspace:v1-favicon.svg";
1414
const expiredUrl = "https://environment.example/api/assets/expired/v1-favicon.svg";

apps/mobile/src/components/projectFaviconCache.ts renamed to apps/mobile/src/lib/projectFaviconRequests.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* Request bookkeeping behind `ProjectFavicon`: tracks the favicon URLs with
3+
* mounted views per cache key, keeps one of them current, and remembers which
4+
* keys have already loaded so superseded or already-shown loads settle without
5+
* churn. This is not request coalescing — each mount still issues its own
6+
* load — and it is not the cache; persistence lives in
7+
* `projectFaviconDatabaseCache`.
8+
*/
19
export interface ProjectFaviconRequest {
210
readonly cacheKey: string;
311
readonly faviconUrl: string;

‎apps/mobile/src/state/assets.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useCallback } from "react";
1616

1717
import { environmentCatalog } from "../connection/catalog";
1818
import { connectionAtomRuntime } from "../connection/runtime";
19-
import { projectFaviconCache } from "../lib/projectFaviconCache";
19+
import { projectFaviconDatabaseCache } from "../lib/projectFaviconDatabaseCache";
2020
import { type AssetUrlState, deriveAssetUrlState } from "./asset-url-state";
2121
import { environmentSession, usePreparedConnection } from "./session";
2222
import { useAtomQueryRunner } from "./use-atom-query-runner";
@@ -26,7 +26,7 @@ export type { AssetUrlFailureReason, AssetUrlState } from "./asset-url-state";
2626
export const assetEnvironment = createAssetEnvironmentAtoms(connectionAtomRuntime);
2727

2828
export const projectFaviconUrlAtom = createProjectFaviconUrlAtomFamily({
29-
imageCache: projectFaviconCache,
29+
imageCache: projectFaviconDatabaseCache,
3030
createUrl: assetEnvironment.createUrl,
3131
preparedConnection: environmentSession.preparedConnectionValueAtom,
3232
});

‎apps/mobile/src/state/client-cache-state.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Effect from "effect/Effect";
33
import { Atom } from "effect/unstable/reactivity";
44

55
import { type ClientCacheKind, MobileDatabase } from "../persistence/mobile-database";
6-
import { projectFaviconCache } from "../lib/projectFaviconCache";
6+
import { projectFaviconDatabaseCache } from "../lib/projectFaviconDatabaseCache";
77
import * as Runtime from "../lib/runtime";
88

99
export interface EnvironmentClientCacheSummary {
@@ -74,8 +74,8 @@ export const clearClientCacheAtom = clientCacheRuntime
7474
.fn((scope: ClientCacheClearScope, get) =>
7575
Effect.promise(() =>
7676
scope.type === "all"
77-
? projectFaviconCache.clearAll()
78-
: projectFaviconCache.clearEnvironment(scope.environmentId),
77+
? projectFaviconDatabaseCache.clearAll()
78+
: projectFaviconDatabaseCache.clearEnvironment(scope.environmentId),
7979
).pipe(
8080
Effect.andThen(MobileDatabase),
8181
Effect.flatMap((database) =>

0 commit comments

Comments
 (0)