quak collections reads the collection list alone (closes #210)
check / check (push) Waiting to run
check / check (push) Waiting to run
On an empty cache the read commands opened their library with a refresh that fetched and decrypted the files of every collection in turn, printing nothing and storing nothing until it had them all, so `quak collections` seemed to hang on a large account. The new `lib.freshCollections()` is the fresh read of the collection list alone: one request, and nothing stored, so a later refresh still fetches every collection's files. The read commands open their library with the new `refreshOnOpen: false` and make only the refresh they ask for. A refresh sends a "progress" event after each collection whose files it fetched; the commands that wait on one print it on stderr, except with `--json`. Model: opus-5-5
This commit was merged in pull request #214.
This commit is contained in:
@@ -14,6 +14,9 @@
|
||||
* three.
|
||||
* 3. A refresh that fails rejects the fresh read (currency was unavailable),
|
||||
* while the default reads stay silent and keep serving the last good copy.
|
||||
* 4. `freshCollections()` reads the collection list alone, with one request
|
||||
* and no collection's files, and stores nothing, so the next refresh still
|
||||
* fetches the files of every collection (issue #210).
|
||||
*
|
||||
* The client is the same metadata-only mock the background-refresh tests use:
|
||||
* no crypto, no network, scripted pages, and a record of each call. A long
|
||||
@@ -270,3 +273,70 @@ describe("Library.fresh", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Library.freshCollections", () => {
|
||||
let dir: string;
|
||||
let cacheDirectory: string;
|
||||
|
||||
beforeEach(() => {
|
||||
dir = mkdtempSync(join(tmpdir(), "quak-fresh-collections-"));
|
||||
cacheDirectory = join(dir, "cache");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
// A refresh fetches a collection's files only when the collection is new
|
||||
// or its updationTime has advanced past the stored copy's. Had the
|
||||
// collection list been stored, the next refresh would take every
|
||||
// collection for one it already holds the files of, and fetch none.
|
||||
it("asks for the collection list alone and stores nothing", async () => {
|
||||
const client = new MockClient();
|
||||
const page = {
|
||||
collections: [collection(2, 100), collection(1, 110)],
|
||||
deleted: [],
|
||||
cursor: 110,
|
||||
};
|
||||
client.collectionsQueue.push(page, page);
|
||||
client.filesFor(1, {
|
||||
files: [file(1001, 1, 90)],
|
||||
deleted: [],
|
||||
cursor: 90,
|
||||
});
|
||||
client.filesFor(2, {
|
||||
files: [file(2001, 2, 95)],
|
||||
deleted: [],
|
||||
cursor: 95,
|
||||
});
|
||||
|
||||
const lib = await Library.open({
|
||||
client,
|
||||
cacheDirectory,
|
||||
refreshOnOpen: false,
|
||||
refreshIntervalSeconds: SLOW_INTERVAL,
|
||||
});
|
||||
try {
|
||||
// One request, the whole list in the server's order, and no
|
||||
// collection's files.
|
||||
const collections = await lib.freshCollections();
|
||||
expect(collections.map((c) => c.id)).toEqual([2, 1]);
|
||||
expect(collections.map((c) => c.name)).toEqual([
|
||||
"album-2",
|
||||
"album-1",
|
||||
]);
|
||||
expect(client.collectionsSinceTimes).toEqual([0]);
|
||||
expect(client.filesCalls).toEqual([]);
|
||||
expect(lib.listCollections()).toEqual([]);
|
||||
|
||||
// The next refresh still asks from the beginning and fetches the
|
||||
// files of both collections.
|
||||
const reads = await lib.fresh();
|
||||
expect(client.collectionsSinceTimes).toEqual([0, 0]);
|
||||
expect(reads.photos.byID({ fileID: 1001 })?.fileID).toBe(1001);
|
||||
expect(reads.photos.byID({ fileID: 2001 })?.fileID).toBe(2001);
|
||||
} finally {
|
||||
await lib.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user