chore(mobile): name the two project favicon caches by their job (#13160)
This commit is contained in:
1 parent
ec28eefa0d
commit
3409651912
8 files changed
+31
-15
No files matched your search
@@ -18,7 +18,7 @@ import {
|
||||
hasLoadedProjectFavicon,
|
||||
markProjectFaviconFailed,
|
||||
markProjectFaviconLoaded,
|
||||
} from "./projectFaviconCache";
|
||||
} from "../lib/projectFaviconRequests";
|
||||
|
||||
const EMPTY_FAVICON_URL = Atom.make<string | null>(null);
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@ import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import * as MobileDatabase from "../persistence/mobile-database";
|
||||
import { attachProjectFaviconDatabase, projectFaviconCache } from "../lib/projectFaviconCache";
|
||||
import {
|
||||
attachProjectFaviconDatabase,
|
||||
projectFaviconDatabaseCache,
|
||||
} from "../lib/projectFaviconDatabaseCache";
|
||||
|
||||
const SHELL_SNAPSHOT_CACHE_SCHEMA_VERSION = 1;
|
||||
// v3 adds windowed (paginated) snapshots carrying `page` metadata; the bump
|
||||
@@ -130,7 +133,7 @@ export const make = Effect.fn("MobileEnvironmentCacheStore.make")(function* () {
|
||||
decode: decodeStoredShellSnapshot,
|
||||
select: (stored) =>
|
||||
stored.environmentId === environmentId ? Option.some(stored.snapshot) : Option.none(),
|
||||
}).pipe(Effect.tap(() => Effect.promise(() => projectFaviconCache.hydrate()))),
|
||||
}).pipe(Effect.tap(() => Effect.promise(() => projectFaviconDatabaseCache.hydrate()))),
|
||||
),
|
||||
saveShell: Effect.fn("MobileEnvironmentCache.saveShell")(function* (environmentId, snapshot) {
|
||||
const payload = yield* encodeStoredShellSnapshot({
|
||||
@@ -241,7 +244,7 @@ export const make = Effect.fn("MobileEnvironmentCacheStore.make")(function* () {
|
||||
.pipe(Effect.mapError(mapDatabaseError("clear-vcs-refs"))),
|
||||
),
|
||||
clear: Effect.fn("MobileEnvironmentCache.clear")((environmentId) =>
|
||||
Effect.promise(() => projectFaviconCache.clearEnvironment(environmentId)).pipe(
|
||||
Effect.promise(() => projectFaviconDatabaseCache.clearEnvironment(environmentId)).pipe(
|
||||
Effect.andThen(database.clearEnvironmentCache(environmentId)),
|
||||
Effect.mapError(mapDatabaseError("clear-environment")),
|
||||
),
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ vi.mock("expo-file-system", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
import { downscaleProjectFavicon } from "./projectFaviconCache";
|
||||
import { downscaleProjectFavicon } from "./projectFaviconDatabaseCache";
|
||||
|
||||
const png = "iVBORw0KGgoAAAAA";
|
||||
const image = { url: "https://remote/icon.png" };
|
||||
+8
-3
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
createProjectFaviconCache,
|
||||
createProjectFaviconCache as createSharedProjectFaviconCache,
|
||||
createProjectFaviconImageLoader,
|
||||
PROJECT_FAVICON_MAX_DATA_URL_LENGTH,
|
||||
PROJECT_FAVICON_THUMBNAIL_SIZE,
|
||||
@@ -78,8 +78,13 @@ export async function downscaleProjectFavicon(
|
||||
throw new Error("Project icon thumbnail exceeds the cache limit.");
|
||||
}
|
||||
|
||||
/** Rows live in `client_cache` so Settings → Client storage counts and clears them. */
|
||||
export const projectFaviconCache = createProjectFaviconCache({
|
||||
/**
|
||||
* The database-backed project favicon cache. Named apart from the shared
|
||||
* `createProjectFaviconCache` factory it calls and from the in-flight request
|
||||
* registry in `projectFaviconRequests`. Rows live in `client_cache` so
|
||||
* Settings → Client storage counts and clears them.
|
||||
*/
|
||||
export const projectFaviconDatabaseCache = createSharedProjectFaviconCache({
|
||||
storage: {
|
||||
list: () =>
|
||||
runDatabase((database) =>
|
||||
+2
-2
@@ -6,9 +6,9 @@ import {
|
||||
hasLoadedProjectFavicon,
|
||||
markProjectFaviconFailed,
|
||||
markProjectFaviconLoaded,
|
||||
} from "./projectFaviconCache";
|
||||
} from "./projectFaviconRequests";
|
||||
|
||||
describe("project favicon cache", () => {
|
||||
describe("project favicon requests", () => {
|
||||
it("ignores callbacks from a superseded URL", () => {
|
||||
const cacheKey = "environment-1:/workspace:v1-favicon.svg";
|
||||
const expiredUrl = "https://environment.example/api/assets/expired/v1-favicon.svg";
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/**
|
||||
* Request bookkeeping behind `ProjectFavicon`: tracks the favicon URLs with
|
||||
* mounted views per cache key, keeps one of them current, and remembers which
|
||||
* keys have already loaded so superseded or already-shown loads settle without
|
||||
* churn. This is not request coalescing — each mount still issues its own
|
||||
* load — and it is not the cache; persistence lives in
|
||||
* `projectFaviconDatabaseCache`.
|
||||
*/
|
||||
export interface ProjectFaviconRequest {
|
||||
readonly cacheKey: string;
|
||||
readonly faviconUrl: string;
|
||||
@@ -16,7 +16,7 @@ import { useCallback } from "react";
|
||||
|
||||
import { environmentCatalog } from "../connection/catalog";
|
||||
import { connectionAtomRuntime } from "../connection/runtime";
|
||||
import { projectFaviconCache } from "../lib/projectFaviconCache";
|
||||
import { projectFaviconDatabaseCache } from "../lib/projectFaviconDatabaseCache";
|
||||
import { type AssetUrlState, deriveAssetUrlState } from "./asset-url-state";
|
||||
import { environmentSession, usePreparedConnection } from "./session";
|
||||
import { useAtomQueryRunner } from "./use-atom-query-runner";
|
||||
@@ -26,7 +26,7 @@ export type { AssetUrlFailureReason, AssetUrlState } from "./asset-url-state";
|
||||
export const assetEnvironment = createAssetEnvironmentAtoms(connectionAtomRuntime);
|
||||
|
||||
export const projectFaviconUrlAtom = createProjectFaviconUrlAtomFamily({
|
||||
imageCache: projectFaviconCache,
|
||||
imageCache: projectFaviconDatabaseCache,
|
||||
createUrl: assetEnvironment.createUrl,
|
||||
preparedConnection: environmentSession.preparedConnectionValueAtom,
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as Effect from "effect/Effect";
|
||||
import { Atom } from "effect/unstable/reactivity";
|
||||
|
||||
import { type ClientCacheKind, MobileDatabase } from "../persistence/mobile-database";
|
||||
import { projectFaviconCache } from "../lib/projectFaviconCache";
|
||||
import { projectFaviconDatabaseCache } from "../lib/projectFaviconDatabaseCache";
|
||||
import * as Runtime from "../lib/runtime";
|
||||
|
||||
export interface EnvironmentClientCacheSummary {
|
||||
@@ -74,8 +74,8 @@ export const clearClientCacheAtom = clientCacheRuntime
|
||||
.fn((scope: ClientCacheClearScope, get) =>
|
||||
Effect.promise(() =>
|
||||
scope.type === "all"
|
||||
? projectFaviconCache.clearAll()
|
||||
: projectFaviconCache.clearEnvironment(scope.environmentId),
|
||||
? projectFaviconDatabaseCache.clearAll()
|
||||
: projectFaviconDatabaseCache.clearEnvironment(scope.environmentId),
|
||||
).pipe(
|
||||
Effect.andThen(MobileDatabase),
|
||||
Effect.flatMap((database) =>
|
||||
|
||||
Reference in new issue
Block a user