Skip to content

Commit

Permalink
fix: properly initialize persisted worker cache
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Aug 27, 2024
1 parent 07d4753 commit 015d8d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/experiments/src/data-worker/cache-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { CacheHandler as CacheHandlerType, Future, NextFn } from '@ember-data/request';
import type Store from '@ember-data/store';
import type { StoreRequestContext } from '@ember-data/store';
import { DEBUG } from '@warp-drive/build-config/env';
import { assert } from '@warp-drive/build-config/macros';
import type { ExistingRecordIdentifier, StableDocumentIdentifier } from '@warp-drive/core-types/identifier';
import type {
Expand Down Expand Up @@ -49,7 +50,11 @@ export const CacheHandler: CacheHandlerType = {
}
return completeRequest(identifier, store, context, next);
})
.catch(() => {
.catch((e) => {
if (DEBUG) {
// eslint-disable-next-line no-console
console.log('Unable to retrieve document from persisted storage', e);
}
return completeRequest(identifier, store, context, next);
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/experiments/src/document-storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function safeDocumentSerialize<T>(document: T): T {
return newDoc as T;
}

function prepareRequest(request: StoreRequestContext['request']): { signal: AbortSignal | null; request: RequestInfo } {
function prepareRequest(request: StoreRequestContext['request']): RequestInfo {
const { signal, headers } = request;
const requestCopy = Object.assign({}, request) as RequestInfo;

Expand All @@ -328,7 +328,7 @@ function prepareRequest(request: StoreRequestContext['request']): { signal: Abor
requestCopy.headers = Array.from(headers.entries()) as unknown as Headers;
}

return { signal: signal || null, request: requestCopy };
return requestCopy;
}

type Mutable<T> = { -readonly [P in keyof T]: T[P] };
Expand Down
3 changes: 2 additions & 1 deletion packages/experiments/src/image-worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ImageWorker {
}
this.threads = new Map();
this.pendingImages = new Map();
this.cache = new Map();
this.options = options || { persisted: false };
this.isSharedWorker = WorkerScope && globalThis instanceof WorkerScope;
this.initialize();
Expand Down Expand Up @@ -96,6 +97,6 @@ export class ImageWorker {

const objectUrl = await this.fetch(url);
const port = this.threads.get(thread)!;
port.postMessage({ type: 'success-response', thread, url: objectUrl });
port.postMessage({ type: 'success-response', thread, url, objectUrl });
}
}

0 comments on commit 015d8d9

Please sign in to comment.