use cached thumbnail if present
This commit is contained in:
parent
40532c85a3
commit
2eae19868c
|
@ -194,7 +194,15 @@ class ClipServiceImpl {
|
|||
if (!token) {
|
||||
return;
|
||||
}
|
||||
const thumb = await downloadManager.downloadThumb(token, file);
|
||||
let thumb: Uint8Array;
|
||||
const thumbURL = await downloadManager.getCachedThumbnail(file);
|
||||
if (thumbURL) {
|
||||
thumb = await fetch(thumbURL)
|
||||
.then((response) => response.arrayBuffer())
|
||||
.then((buffer) => new Uint8Array(buffer));
|
||||
} else {
|
||||
thumb = await downloadManager.downloadThumb(token, file);
|
||||
}
|
||||
const embedding = await this.electronAPIs.computeImageEmbedding(thumb);
|
||||
return embedding;
|
||||
};
|
||||
|
|
|
@ -31,30 +31,29 @@ class DownloadManager {
|
|||
|
||||
private progressUpdater: (value: Map<number, number>) => void = () => {};
|
||||
|
||||
private thumbnailCache: LimitedCache;
|
||||
|
||||
setProgressUpdater(progressUpdater: (value: Map<number, number>) => void) {
|
||||
this.progressUpdater = progressUpdater;
|
||||
}
|
||||
|
||||
private async getThumbnailCache() {
|
||||
try {
|
||||
const thumbnailCache = await CacheStorageService.open(
|
||||
if (!this.thumbnailCache) {
|
||||
this.thumbnailCache = await CacheStorageService.open(
|
||||
CACHES.THUMBS
|
||||
);
|
||||
return thumbnailCache;
|
||||
}
|
||||
return this.thumbnailCache;
|
||||
} catch (e) {
|
||||
return null;
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
public async getCachedThumbnail(
|
||||
file: EnteFile,
|
||||
thumbnailCache?: LimitedCache
|
||||
) {
|
||||
public async getCachedThumbnail(file: EnteFile) {
|
||||
try {
|
||||
if (!thumbnailCache) {
|
||||
thumbnailCache = await this.getThumbnailCache();
|
||||
}
|
||||
const thumbnailCache = await this.getThumbnailCache();
|
||||
const cacheResp: Response = await thumbnailCache?.match(
|
||||
file.id.toString()
|
||||
);
|
||||
|
@ -83,10 +82,7 @@ class DownloadManager {
|
|||
if (!this.thumbnailObjectURLPromise.has(file.id)) {
|
||||
const downloadPromise = async () => {
|
||||
const thumbnailCache = await this.getThumbnailCache();
|
||||
const cachedThumb = await this.getCachedThumbnail(
|
||||
file,
|
||||
thumbnailCache
|
||||
);
|
||||
const cachedThumb = await this.getCachedThumbnail(file);
|
||||
if (cachedThumb) {
|
||||
return cachedThumb;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue