quak files COLLECTION fetches that collection's files alone (closes #217)
check / check (push) Waiting to run

`quak files` with a collection ID used to wait for a full refresh, which
on an empty cache fetched the files of every collection in the account.
It now reads the collection list, then that one collection's files
through the new `Library.freshFiles()`, and stores nothing. The files
print in the server's order, and no refresh progress lines appear. Each
file prints once, as the latest copy the server sent. `quak files`
without a collection ID still waits for a refresh.

Some tests ran `quak files` with a collection ID to fill the cache, to
show a refresh's progress or to show what `-q` hides. They now run a
command that still refreshes.

Model: opus-5-5
This commit was merged in pull request #225.
This commit is contained in:
2026-10-26 09:04:39 +01:00
parent 657266a60e
commit af1491966c
8 changed files with 282 additions and 147 deletions
+27 -26
View File
@@ -2,34 +2,35 @@
//
// `collections`, `files`, `get`, and `get-thumb` must answer for
// the account's state at the moment the command runs, not for whatever the
// local cache last happened to hold (owner amendment, issue #36). `files`,
// `get` and `get-thumb` therefore force a server round-trip through
// `Library.fresh()` and only then read — so a collection, file, or metadata
// change made elsewhere is visible. `collections` asks the library for the
// collection list alone through `Library.freshCollections()` (issue #210): a
// refresh would also fetch the files of every collection, which on a large
// account takes long and which `collections` does not print.
// local cache last happened to hold (owner amendment, issue #36). `get`,
// `get-thumb` and `files` without a collection ID therefore force a server
// round-trip through `Library.fresh()` and only then read, so a change made
// elsewhere is visible. `collections` asks the library for the collection list
// alone through `Library.freshCollections()` (issue #210): a refresh would also
// fetch the files of every collection, which on a large account takes long and
// which `collections` does not print. `files` with a collection ID reads that
// list too, then that one collection's files through `Library.freshFiles()`
// (issue #217).
//
// `collections` lists in the server's order and `files` in the library's own
// enumeration order (`listFiles()`), the orders the pre-library CLI printed,
// rather than the `albums`/`photos` projection's newest-first order, which
// re-sorts the rows. The field values still come from each record's raw
// metadata via `cli-output.ts`. `files` without a collection ID lists every
// file in the account once (issue #211): the library keeps a record of a file
// for each collection that holds it, and only the first collection's record is
// listed.
// `collections` and `files` with a collection ID list in the server's order.
// `files` without one lists in the library's own enumeration order
// (`listFiles()`). Neither command uses the `albums`/`photos` projection's
// newest-first order, which re-sorts the rows. The field values still come
// from each record's raw metadata via `cli-output.ts`. `files` without a
// collection ID lists every file in the account once (issue #211): the library
// keeps a record of a file for each collection that holds it, and only the
// first collection's record is listed.
import type { Collection, EnteFile } from "./model/types.js";
import type { Photo, PhotosAPI } from "./library/index.js";
// The slice of `Library` these helpers read. `Library` satisfies it
// structurally; a test can drive them with a stand-in that records the
// `fresh()` and `freshCollections()` calls and serves records in a known
// enumeration order.
// structurally; a test can drive them with a stand-in that records each fresh
// read and serves records in a known enumeration order.
export interface FreshReadLibrary {
fresh(): Promise<unknown>;
freshCollections(): Promise<Collection[]>;
getCollection(id: number): Collection | undefined;
freshFiles(collection: Collection): Promise<EnteFile[]>;
listCollections(): Collection[];
listFiles(collectionID: number): EnteFile[];
getFileByID(fileID: number): EnteFile | undefined;
@@ -42,21 +43,21 @@ export const freshCollections = (
lib: FreshReadLibrary,
): Promise<Collection[]> => lib.freshCollections();
// The files of one collection, current as of a forced refresh, in enumeration
// The files of one collection, as the server holds them now, in the server's
// order. `undefined` (not an empty list) when the collection does not exist, so
// the caller can tell "no such collection" from "an empty collection". Without
// a collection ID, every file in the account, each once, as held by the first
// collection that holds it.
// a collection ID, every file in the account as of a forced refresh, each once,
// as held by the first collection that holds it.
export const freshFiles = async (
lib: FreshReadLibrary,
collectionID?: number,
): Promise<EnteFile[] | undefined> => {
await lib.fresh();
if (collectionID !== undefined) {
return lib.getCollection(collectionID)
? lib.listFiles(collectionID)
: undefined;
const collections = await lib.freshCollections();
const collection = collections.find((c) => c.id === collectionID);
return collection ? lib.freshFiles(collection) : undefined;
}
await lib.fresh();
const listed = new Set<number>();
const files: EnteFile[] = [];
for (const collection of lib.listCollections()) {