perf(clients): saving the thread list cache no longer freezes the UI (#13767)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
1d6f23b519
commit
9151ea407a
5 files changed
+122
-13
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
ConnectionPersistenceError,
|
||||
EnvironmentCacheStore,
|
||||
encodeShellSnapshotForCache,
|
||||
} from "@t3tools/client-runtime/platform";
|
||||
import {
|
||||
type EnvironmentId,
|
||||
@@ -56,7 +57,6 @@ const StoredVcsRefs = Schema.Struct({
|
||||
const decodeStoredShellSnapshot = Schema.decodeUnknownEffect(
|
||||
Schema.fromJsonString(StoredShellSnapshot),
|
||||
);
|
||||
const encodeStoredShellSnapshot = Schema.encodeEffect(Schema.fromJsonString(StoredShellSnapshot));
|
||||
const decodeStoredThreadSnapshot = Schema.decodeUnknownEffect(
|
||||
Schema.fromJsonString(StoredThreadSnapshot),
|
||||
);
|
||||
@@ -136,11 +136,18 @@ export const make = Effect.fn("MobileEnvironmentCacheStore.make")(function* () {
|
||||
}).pipe(Effect.tap(() => Effect.promise(() => projectFaviconDatabaseCache.hydrate()))),
|
||||
),
|
||||
saveShell: Effect.fn("MobileEnvironmentCache.saveShell")(function* (environmentId, snapshot) {
|
||||
const payload = yield* encodeStoredShellSnapshot({
|
||||
schemaVersion: SHELL_SNAPSHOT_CACHE_SCHEMA_VERSION,
|
||||
environmentId,
|
||||
snapshot,
|
||||
}).pipe(Effect.mapError((cause) => persistenceError("save-shell", cause)));
|
||||
const encodedSnapshot = yield* encodeShellSnapshotForCache(snapshot).pipe(
|
||||
Effect.mapError((cause) => persistenceError("save-shell", cause)),
|
||||
);
|
||||
const payload = yield* Effect.try({
|
||||
try: () =>
|
||||
JSON.stringify({
|
||||
schemaVersion: SHELL_SNAPSHOT_CACHE_SCHEMA_VERSION,
|
||||
environmentId,
|
||||
snapshot: encodedSnapshot,
|
||||
} satisfies typeof StoredShellSnapshot.Encoded),
|
||||
catch: (cause) => persistenceError("save-shell", cause),
|
||||
});
|
||||
yield* database
|
||||
.saveCache(environmentId, "shell", "snapshot", SHELL_SNAPSHOT_CACHE_SCHEMA_VERSION, payload)
|
||||
.pipe(Effect.mapError(mapDatabaseError("save-shell")));
|
||||
|
||||
@@ -87,6 +87,29 @@ describe("makeCatalogBackend", () => {
|
||||
expect(setConnectionCatalog).toHaveBeenCalledWith("{}");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("fails IndexedDB writes whose commit aborts", () =>
|
||||
Effect.gen(function* () {
|
||||
vi.stubGlobal("window", {});
|
||||
const transaction = Object.assign(new EventTarget(), {
|
||||
error: null as DOMException | null,
|
||||
objectStore: () => ({
|
||||
put: () => {
|
||||
// A failed commit aborts the transaction without an "error" event.
|
||||
queueMicrotask(() => {
|
||||
transaction.error = new DOMException("Quota exceeded", "QuotaExceededError");
|
||||
transaction.dispatchEvent(new Event("abort"));
|
||||
});
|
||||
},
|
||||
}),
|
||||
});
|
||||
const backend = makeCatalogBackend({ transaction: () => transaction } as never);
|
||||
|
||||
const error = yield* backend.write("{}").pipe(Effect.flip);
|
||||
|
||||
expect(error.message).toContain("QuotaExceededError");
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
describe("browser GitHub routing permissions", () => {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
ConnectionTargetStore,
|
||||
EMPTY_CONNECTION_CATALOG_DOCUMENT,
|
||||
EnvironmentCacheStore,
|
||||
encodeShellSnapshotForCache,
|
||||
putRemoteDpopTokenInCatalog,
|
||||
registerConnectionInCatalog,
|
||||
removeCatalogValue,
|
||||
@@ -91,7 +92,6 @@ const ConnectionCatalogDocumentJson = Schema.fromJsonString(ConnectionCatalogDoc
|
||||
const decodeConnectionCatalogDocument = Schema.decodeUnknownEffect(ConnectionCatalogDocumentJson);
|
||||
const encodeConnectionCatalogDocument = Schema.encodeEffect(ConnectionCatalogDocumentJson);
|
||||
const decodeStoredShellSnapshot = Schema.decodeUnknownEffect(StoredShellSnapshotJson);
|
||||
const encodeStoredShellSnapshot = Schema.encodeEffect(StoredShellSnapshotJson);
|
||||
const decodeStoredThreadSnapshot = Schema.decodeUnknownEffect(StoredThreadSnapshotJson);
|
||||
const encodeStoredThreadSnapshot = Schema.encodeEffect(StoredThreadSnapshotJson);
|
||||
const decodeStoredServerConfig = Schema.decodeUnknownEffect(StoredServerConfigJson);
|
||||
@@ -188,7 +188,9 @@ function writeDatabaseValue(
|
||||
) {
|
||||
return Effect.callback<void, ConnectionTransientError>((resume) => {
|
||||
const transaction = database.transaction(storeName, "readwrite");
|
||||
transaction.addEventListener("error", () => {
|
||||
// Every failed write fires "abort". A failed commit, such as
|
||||
// QuotaExceededError, fires only "abort" and no "error".
|
||||
transaction.addEventListener("abort", () => {
|
||||
resume(
|
||||
Effect.fail(catalogError("write", transaction.error ?? "Unknown IndexedDB write error")),
|
||||
);
|
||||
@@ -606,11 +608,17 @@ export const connectionStorageLayer = Layer.effectContext(
|
||||
),
|
||||
saveShell: (environmentId, snapshot) =>
|
||||
Effect.gen(function* () {
|
||||
const encoded = yield* encodeStoredShellSnapshot({
|
||||
schemaVersion: SHELL_SNAPSHOT_CACHE_SCHEMA_VERSION,
|
||||
environmentId,
|
||||
snapshot,
|
||||
}).pipe(Effect.mapError((cause) => persistenceError("save-shell", cause)));
|
||||
const encodedSnapshot = yield* encodeShellSnapshotForCache(snapshot);
|
||||
const encoded = yield* Effect.try({
|
||||
try: () =>
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off - the snapshot is already encoded.
|
||||
JSON.stringify({
|
||||
schemaVersion: SHELL_SNAPSHOT_CACHE_SCHEMA_VERSION,
|
||||
environmentId,
|
||||
snapshot: encodedSnapshot,
|
||||
} satisfies typeof StoredShellSnapshot.Encoded),
|
||||
catch: (cause) => persistenceError("save-shell", cause),
|
||||
});
|
||||
yield* writeDatabaseValue(database, SHELL_STORE_NAME, environmentId, encoded);
|
||||
}).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
|
||||
Reference in new issue
Block a user