Skip to content

Commit

Permalink
ximg: minor refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <[email protected]>
  • Loading branch information
pulsejet committed Nov 1, 2023
1 parent e2d4a53 commit 44c3ed1
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/components/frame/XImgWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ async function flushPreviewQueue() {
// it came from a multipreview, so that we can try fetching
// the single image instead
blob ??= await res.blob();
pendingUrls.get(url)?.forEach((cb) => {
cb?.resolve?.(blob!);
});
pendingUrls.get(url)?.forEach((cb) => cb?.resolve?.(blob!));
pendingUrls.delete(url);

// Cache response
Expand All @@ -77,9 +75,7 @@ async function flushPreviewQueue() {

// Throw error on URL
const reject = (url: string, e: any): void => {
pendingUrls.get(url)?.forEach((cb) => {
cb?.reject?.(e);
});
pendingUrls.get(url)?.forEach((cb) => cb?.reject?.(e));
pendingUrls.delete(url);
};

Expand Down Expand Up @@ -218,7 +214,6 @@ async function fetchImage(url: string): Promise<Blob> {

// Just fetch if not a preview
const regex = /\/memories\/api\/image\/preview\/\d+(\?.*)?$/;

if (!regex.test(url)) {
const res = await fetchOneImage(url);
cacheResponse(url, res);
Expand Down Expand Up @@ -250,7 +245,7 @@ async function fetchImage(url: string): Promise<Blob> {
fetchPreviewTimer = self.setTimeout(flushPreviewQueue, 20);
}

// If queue has >10 items, flush immediately
// If queue has >20 items, flush immediately
// This will internally clear the timer
if (fetchPreviewQueue.length >= 20) {
flushPreviewQueue();
Expand Down

0 comments on commit 44c3ed1

Please sign in to comment.