cimg: minor improvements

pull/465/head
Varun Patil 2023-03-08 13:14:38 -08:00
parent 0505711a9f
commit a52ef3dc14
2 changed files with 5 additions and 7 deletions

View File

@ -72,20 +72,18 @@ export default defineComponent({
// Check if the blob cache exists // Check if the blob cache exists
if (!usedCache(this.src)) { if (!usedCache(this.src)) {
const src = this.src; const src = this.src;
const newBlob = URL.createObjectURL(await fetchImage(src)); const img = await fetchImage(src);
if (this.src !== src || this.isDestroyed) { if (this.src !== src || this.isDestroyed) {
URL.revokeObjectURL(newBlob); // the src has changed, abort // the src has changed, abort
return; return;
} }
// Check if the blob cache exists now // Check if the blob cache exists now
// In this case, someone else already created the blob // In this case, someone else already created the blob
// Free up the current blob and use the existing one instead // Free up the current blob and use the existing one instead
if (usedCache(src)) { if (!usedCache(src)) {
URL.revokeObjectURL(newBlob);
} else {
// Create new blob cache entry // Create new blob cache entry
this.dataSrc = newBlob; this.dataSrc = URL.createObjectURL(img);
BLOB_CACHE[src] = [1, this.dataSrc]; BLOB_CACHE[src] = [1, this.dataSrc];
} }
} }

View File

@ -84,7 +84,7 @@ async function flushPreviewQueue() {
fetchPreviewQueueCopy fetchPreviewQueueCopy
.filter((p) => p.reqid === reqid) .filter((p) => p.reqid === reqid)
.forEach((p) => { .forEach((p) => {
p.callback(getResponse(imgBlob, imgType, res.headers)); p.callback?.(getResponse(imgBlob, imgType, res.headers));
p.callback = null; p.callback = null;
}); });
} }