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

View File

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