Write each backed-up original once and skip the precache (closes #106)
check / check (push) Successful in 49s
check / check (push) Successful in 49s
An original fetched for a backup is now written by the download writer straight into the backup's originals/, and the content cache records it there instead of keeping its own copy. One the cache already held is still copied. `quak backup` opens its library with the thumbnail and originals precache off, as the one-shot commands do. Model: opus-5-5
This commit was merged in pull request #124.
This commit is contained in:
+21
-3
@@ -321,6 +321,23 @@ export class ContentCache implements PhotoContent, ThumbnailsAPI {
|
||||
return this.get(fileID, "thumbnail", "on-demand", opts?.onProgress);
|
||||
}
|
||||
|
||||
// Get an original for a backup. One not present anywhere is written
|
||||
// straight to `destination` and recorded there, so no second copy lands
|
||||
// in the cache; one already present is returned where it is.
|
||||
async backupOriginal(
|
||||
fileID: number,
|
||||
destination: string,
|
||||
): Promise<ContentResult> {
|
||||
const result = await this.acquire(
|
||||
fileID,
|
||||
"original",
|
||||
"on-demand",
|
||||
undefined,
|
||||
{ destination },
|
||||
);
|
||||
return { path: result.path, bytes: result.bytes };
|
||||
}
|
||||
|
||||
async ensure(args: EnsureOptions): Promise<EnsureResult[]> {
|
||||
return this.ensureThumbnails(args);
|
||||
}
|
||||
@@ -422,13 +439,14 @@ export class ContentCache implements PhotoContent, ThumbnailsAPI {
|
||||
|
||||
// The core: return the cached path if present, else fetch through the pool,
|
||||
// store, and return it. `cached` distinguishes a present hit (no network,
|
||||
// no download event) from a fresh fetch.
|
||||
// no download event) from a fresh fetch. A fetched original is stored at
|
||||
// `opts.destination` when given, instead of in `originalsDir`.
|
||||
private async acquire(
|
||||
fileID: number,
|
||||
kind: Kind,
|
||||
priority: Priority,
|
||||
signal: AbortSignal | undefined,
|
||||
opts?: { onByte?: ProgressCallback },
|
||||
opts?: { onByte?: ProgressCallback; destination?: string },
|
||||
): Promise<{ path: string; bytes: number; cached: boolean }> {
|
||||
const file = this.getFile(fileID);
|
||||
if (!file) throw new Error(`content cache: unknown file ${fileID}`);
|
||||
@@ -469,7 +487,7 @@ export class ContentCache implements PhotoContent, ThumbnailsAPI {
|
||||
kind === "original" ? this.originalsDir : this.thumbnailsDir;
|
||||
const dest =
|
||||
kind === "original"
|
||||
? join(dir, originalName(file))
|
||||
? (opts?.destination ?? join(dir, originalName(file)))
|
||||
: join(dir, `${fileID}${THUMBNAIL_EXT}`);
|
||||
const pool =
|
||||
kind === "original" ? this.pools.content : this.pools.thumbnails;
|
||||
|
||||
@@ -571,7 +571,8 @@ export class Library {
|
||||
refresh: () => this.refreshNow(),
|
||||
listCollections: () => this.store.listCollections(),
|
||||
listFiles: (id) => this.store.listFiles(id),
|
||||
original: (fileID) => cache!.original(fileID),
|
||||
original: (fileID, destination) =>
|
||||
cache!.backupOriginal(fileID, destination),
|
||||
thumbnail: (fileID) => cache!.thumbnail(fileID),
|
||||
},
|
||||
{ ...opts, downloadDirectory },
|
||||
|
||||
Reference in New Issue
Block a user