Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Most recent file IDs first

Manav Rathicf3b75702192
diff --git a/web/packages/new/photos/services/ml/db.ts b/web/packages/new/photos/services/ml/db.ts
index 7252483845..91f0dd21fa 100644
--- a/web/packages/new/photos/services/ml/db.ts
+++ b/web/packages/new/photos/services/ml/db.ts
@@ -394,14 +394,23 @@ export const indexableAndIndexedCounts = async () => {
* universe, we filter out fileIDs the files corresponding to which have already
* been indexed, or which should be ignored.
*
- * @param count Limit the result to up to {@link count} items.
+ * @param count Limit the result to up to {@link count} items. If there are more
+ * than {@link count} items present, the files with the higher file IDs (which
+ * can be taken as a approximate for their creation order) are preferred.
*/
-export const indexableFileIDs = async (count?: number) => {
+export const indexableFileIDs = async (count: number) => {
const db = await mlDB();
const tx = db.transaction("file-status", "readonly");
- return tx.store
+ let cursor = await tx.store
.index("status")
- .getAllKeys(IDBKeyRange.only("indexable"), count);
+ .openKeyCursor(IDBKeyRange.only("indexable"), "prev");
+ const result: number[] = [];
+ while (cursor && count > 0) {
+ result.push(cursor.primaryKey);
+ cursor = await cursor.continue();
+ count -= 1;
+ }
+ return result;
};
/**
diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.ts
index 79520cc076..27dd602aef 100644
--- a/web/packages/new/photos/services/ml/worker.ts
+++ b/web/packages/new/photos/services/ml/worker.ts
@@ -339,6 +339,8 @@ const indexNextBatch = async (
* about. Then return the next {@link count} files that still need to be
* indexed.
*
+ * When returning from amongst pending files, prefer the most recent ones first.
+ *
* For specifics of what a "sync" entails, see {@link updateAssumingLocalFiles}.
*
* @param userID Sync only files owned by a {@link userID} with the face DB.