Skip to content

armgit / ente

Public Imported from GitHub
0

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

norm + hidden - fin

Manav Rathic66ee58d8537
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index 2328da5fc9..5c4013fb65 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -18,7 +18,6 @@ import {
CollectionSummaryOrder,
CollectionsSortBy,
} from "ente-new/photos/services/collection-summary";
-import { getLocalCollections } from "ente-new/photos/services/collections";
import {
savedCollectionFiles,
savedCollections,
@@ -231,7 +230,7 @@ export const deleteCollection = async (
* Return the user's own favorites collection, if any.
*/
export const getFavCollection = async () => {
- const collections = await getLocalCollections();
+ const collections = await savedCollections();
const userID = ensureLocalUser().id;
for (const collection of collections) {
// See: [Note: User and shared favorites]
@@ -285,7 +284,7 @@ function compareCollectionsLatestFile(
}
export async function getDefaultHiddenCollection(): Promise<Collection> {
- const collections = await getLocalCollections("hidden");
+ const collections = await savedCollections();
const hiddenCollection = collections.find((collection) =>
isDefaultHiddenCollection(collection),
);
diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.ts
index ae3a38221f..fd1c65b8a7 100644
--- a/web/apps/photos/src/services/upload-manager.ts
+++ b/web/apps/photos/src/services/upload-manager.ts
@@ -36,7 +36,7 @@ import {
} from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
import { potentialFileTypeFromExtension } from "ente-media/live-photo";
-import { getLocalFiles } from "ente-new/photos/services/files";
+import { savedNormalCollectionFiles } from "ente-new/photos/services/file";
import { indexNewUpload } from "ente-new/photos/services/ml";
import { wait } from "ente-utils/promise";
import {
@@ -448,7 +448,9 @@ class UploadManager {
),
);
} else {
- this.existingFiles = getUserOwnedFiles(await getLocalFiles());
+ this.existingFiles = getUserOwnedFiles(
+ await savedNormalCollectionFiles(),
+ );
}
this.collections = new Map(
collections.map((collection) => [collection.id, collection]),
diff --git a/web/apps/photos/src/services/watch.ts b/web/apps/photos/src/services/watch.ts
index 435d22b2d7..bb8a821786 100644
--- a/web/apps/photos/src/services/watch.ts
+++ b/web/apps/photos/src/services/watch.ts
@@ -16,7 +16,7 @@ import { type UploadResult } from "ente-gallery/services/upload";
import type { UploadAsset } from "ente-gallery/services/upload/upload-service";
import { groupFilesByCollectionID } from "ente-gallery/utils/files";
import type { EnteFile } from "ente-media/file";
-import { getLocalFiles } from "ente-new/photos/services/files";
+import { savedNormalCollectionFiles } from "ente-new/photos/services/file";
import { ensureString } from "ente-utils/ensure";
import { removeFromCollection } from "./collectionService";
import { type UploadItemWithCollection, uploadManager } from "./upload-manager";
@@ -475,7 +475,7 @@ class FolderWatcher {
for (const file of syncedFiles)
syncedFileForID.set(file.uploadedFileID, file);
- const files = await getLocalFiles();
+ const files = await savedNormalCollectionFiles();
const filesToTrash = files.filter((file) => {
const correspondingSyncedFile = syncedFileForID.get(file.id);
if (
diff --git a/web/apps/photos/tests/upload.test.ts b/web/apps/photos/tests/upload.test.ts
index 8421e00850..3a8f30889c 100644
--- a/web/apps/photos/tests/upload.test.ts
+++ b/web/apps/photos/tests/upload.test.ts
@@ -14,8 +14,10 @@ import {
fileLocation,
} from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
-import { getLocalCollections } from "ente-new/photos/services/collections";
-import { savedCollectionFiles } from "ente-new/photos/services/photos-fdb";
+import {
+ savedCollectionFiles,
+ savedCollections,
+} from "ente-new/photos/services/photos-fdb";
import { getUserDetailsV2 } from "ente-new/photos/services/user-details";
const DATE_TIME_PARSING_TEST_FILE_NAMES = [
@@ -179,7 +181,7 @@ async function totalFileCountCheck(expectedState) {
}
async function totalCollectionCountCheck(expectedState) {
- const collections = await getLocalCollections();
+ const collections = await savedCollections();
if (expectedState.collection_count === collections.length) {
console.log("collection count check passed βœ…");
} else {
@@ -192,7 +194,7 @@ async function totalCollectionCountCheck(expectedState) {
async function collectionWiseFileCount(expectedState) {
const files = await savedCollectionFiles();
- const collections = await getLocalCollections();
+ const collections = await savedCollections();
const collectionToFilesMap = groupFilesByCollectionID(files);
const collectionIDToNameMap = new Map(
collections.map((collection) => [collection.id, collection.name]),
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index b88ce419a7..2e13cc350b 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -14,7 +14,7 @@ import { fileLogID, type EnteFile } from "ente-media/file";
import { FileType } from "ente-media/file-type";
import { updateFilePublicMagicMetadata } from "ente-new/photos/services/file";
import { savedCollectionFiles } from "ente-new/photos/services/photos-fdb";
-import { getLocalTrashFileIDs } from "ente-new/photos/services/trash";
+import { savedTrashItemFileIDs } from "ente-new/photos/services/trash";
import { gunzip, gzip } from "ente-new/photos/utils/gzip";
import { randomSample } from "ente-utils/array";
import { ensurePrecondition } from "ente-utils/ensure";
@@ -878,7 +878,7 @@ const backfillQueue = async (
userID: number,
): Promise<VideoProcessingQueueItem[]> => {
const allCollectionFiles = await savedCollectionFiles();
- const localTrashFileIDs = await getLocalTrashFileIDs();
+ const localTrashFileIDs = await savedTrashItemFileIDs();
const videoFiles = uniqueFilesByID(
allCollectionFiles.filter(
(f) =>
diff --git a/web/packages/new/photos/components/ImageEditorOverlay.tsx b/web/packages/new/photos/components/ImageEditorOverlay.tsx
index ed0e84f13b..47b469029d 100644
--- a/web/packages/new/photos/components/ImageEditorOverlay.tsx
+++ b/web/packages/new/photos/components/ImageEditorOverlay.tsx
@@ -50,7 +50,6 @@ import { downloadManager } from "ente-gallery/services/download";
import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import { fileFileName } from "ente-media/file-metadata";
-import { getLocalCollections } from "ente-new/photos/services/collections";
import { t } from "i18next";
import React, {
forwardRef,
@@ -61,6 +60,7 @@ import React, {
type Ref,
type RefObject,
} from "react";
+import { savedCollections } from "../services/photos-fdb";
export type ImageEditorOverlayProps = ModalVisibilityProps & {
/**
@@ -478,7 +478,7 @@ export const ImageEditorOverlay: React.FC<ImageEditorOverlayProps> = ({
const saveCopyToEnte = async () => {
if (!canvasRef.current) return;
try {
- const collections = await getLocalCollections();
+ const collections = await savedCollections();
const collection = collections.find(
(c) => c.id == file.collectionID,
);
diff --git a/web/packages/new/photos/services/collections.ts b/web/packages/new/photos/services/collections.ts
index ae4e165311..9fbaa92c82 100644
--- a/web/packages/new/photos/services/collections.ts
+++ b/web/packages/new/photos/services/collections.ts
@@ -1,20 +1,11 @@
import { type Collection } from "ente-media/collection";
import localForage from "ente-shared/storage/localForage";
-import { getCollections, isHiddenCollection } from "./collection";
+import { getCollections } from "./collection";
import { savedCollections } from "./photos-fdb";
const COLLECTION_TABLE = "collections";
const COLLECTION_UPDATION_TIME = "collection-updation-time";
-export const getLocalCollections = async (
- type: "normal" | "hidden" = "normal",
-): Promise<Collection[]> => {
- const collections = await savedCollections();
- return type == "normal"
- ? collections.filter((c) => !isHiddenCollection(c))
- : collections.filter((c) => isHiddenCollection(c));
-};
-
export const getCollectionLastSyncTime = async (collection: Collection) =>
(await localForage.getItem<number>(`${collection.id}-time`)) ?? 0;
diff --git a/web/packages/new/photos/services/dedup.ts b/web/packages/new/photos/services/dedup.ts
index 7991f77825..d3d1c78612 100644
--- a/web/packages/new/photos/services/dedup.ts
+++ b/web/packages/new/photos/services/dedup.ts
@@ -9,7 +9,6 @@ import {
moveToTrash,
savedNormalCollections,
} from "./collection";
-import { getLocalCollections } from "./collections";
import { savedCollectionFiles } from "./photos-fdb";
import { syncCollectionAndFiles } from "./sync";
@@ -277,7 +276,7 @@ export const removeSelectedDuplicateGroups = async (
const tickProgress = () => onProgress((np++ / ntotal) * 100);
// Process the adds.
- const collections = await getLocalCollections("normal");
+ const collections = await savedNormalCollections();
const collectionsByID = new Map(collections.map((c) => [c.id, c]));
for (const [collectionID, files] of filesToAdd.entries()) {
await addToCollection(collectionsByID.get(collectionID)!, files);
diff --git a/web/packages/new/photos/services/export-migration.ts b/web/packages/new/photos/services/export-migration.ts
index 6ed083c63b..5685c5de12 100644
--- a/web/packages/new/photos/services/export-migration.ts
+++ b/web/packages/new/photos/services/export-migration.ts
@@ -14,7 +14,6 @@ import { type EnteFile } from "ente-media/file";
import { fileFileName } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
import { decodeLivePhoto } from "ente-media/live-photo";
-import { getLocalCollections } from "ente-new/photos/services/collections";
import {
safeDirectoryName,
safeFileName,
@@ -32,7 +31,7 @@ import exportService, {
type ExportStage,
type FileExportNames,
} from "./export";
-import { savedFiles } from "./photos-fdb";
+import { savedCollectionFiles, savedCollections } from "./photos-fdb";
type ExportedCollectionPaths = Record<number, string>;
@@ -140,8 +139,8 @@ async function migrationV0ToV1(
}
const collectionIDPathMap = new Map<number, string>();
const user: User = getData("user");
- const localFiles = await savedFiles();
- const localCollections = await getLocalCollections();
+ const localFiles = await savedCollectionFiles();
+ const localCollections = await savedCollections();
const personalFiles = getIDBasedSortedFiles(
localFiles.filter((file) => file.ownerID == user.id),
);
@@ -179,7 +178,7 @@ async function migrationV2ToV3(
return;
}
const user: User = getData("user");
- const localFiles = await savedFiles();
+ const localFiles = await savedCollectionFiles();
const personalFiles = getIDBasedSortedFiles(
localFiles.filter((file) => file.ownerID == user.id),
);
diff --git a/web/packages/new/photos/services/export.ts b/web/packages/new/photos/services/export.ts
index 116e0d88f1..c8df22cedb 100644
--- a/web/packages/new/photos/services/export.ts
+++ b/web/packages/new/photos/services/export.ts
@@ -36,7 +36,7 @@ import { getData, setData } from "ente-shared/storage/localStorage";
import { PromiseQueue } from "ente-utils/promise";
import i18n from "i18next";
import { migrateExport, type ExportRecord } from "./export-migration";
-import { savedCollections, savedFiles } from "./photos-fdb";
+import { savedCollectionFiles, savedCollections } from "./photos-fdb";
/** Name of the JSON file in which we keep the state of the export. */
const exportRecordFileName = "export_status.json";
@@ -251,7 +251,11 @@ class ExportService {
* happen.
*/
pendingFiles = async (exportRecord?: ExportRecord): Promise<EnteFile[]> => {
- return getUnExportedFiles(await savedFiles(), exportRecord, undefined);
+ return getUnExportedFiles(
+ await savedCollectionFiles(),
+ exportRecord,
+ undefined,
+ );
};
async preExport(exportFolder: string) {
@@ -357,7 +361,7 @@ class ExportService {
{ resync }: ExportOpts,
) {
try {
- const files = await savedFiles();
+ const files = await savedCollectionFiles();
const collections = await savedCollections();
const exportRecord = await this.getExportRecord(exportFolder);
diff --git a/web/packages/new/photos/services/file.ts b/web/packages/new/photos/services/file.ts
index 6106821e1c..16d3987840 100644
--- a/web/packages/new/photos/services/file.ts
+++ b/web/packages/new/photos/services/file.ts
@@ -12,6 +12,8 @@ import {
type RemoteMagicMetadata,
} from "ente-media/magic-metadata";
import { batch } from "ente-utils/array";
+import { savedHiddenCollections } from "./collection";
+import { savedCollectionFiles } from "./photos-fdb";
/**
* An reasonable but otherwise arbitrary number of items (e.g. files) to include
@@ -46,6 +48,20 @@ export const performInBatches = <T, U>(
op: (batchItems: T[]) => Promise<U>,
): Promise<U[]> => Promise.all(batch(items, requestBatchSize).map(op));
+/**
+ * Return the list of collection files from our local database that do not
+ * belong to hidden collections.
+ */
+export const savedNormalCollectionFiles = async () => {
+ const hiddenCollections = await savedHiddenCollections();
+ const hiddenCollectionIDs = new Set(hiddenCollections.map((c) => c.id));
+
+ const collectionFiles = await savedCollectionFiles();
+ return collectionFiles.filter(
+ (f) => !hiddenCollectionIDs.has(f.collectionID),
+ );
+};
+
/**
* Change the visibility (normal, archived, hidden) of a list of files on
* remote.
diff --git a/web/packages/new/photos/services/ml/db.ts b/web/packages/new/photos/services/ml/db.ts
index a253803919..7e67209032 100644
--- a/web/packages/new/photos/services/ml/db.ts
+++ b/web/packages/new/photos/services/ml/db.ts
@@ -344,7 +344,7 @@ export const getIndexableAndIndexedCounts = async () => {
* 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 getIndexableFileIDs = async (count: number) => {
+export const readNextIndexableFileIDs = async (count: number) => {
const db = await mlDB();
const tx = db.transaction("file-status", "readonly");
let cursor = await tx.store
diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts
index 2202edf92b..692228b473 100644
--- a/web/packages/new/photos/services/ml/people.ts
+++ b/web/packages/new/photos/services/ml/people.ts
@@ -3,8 +3,7 @@ import log from "ente-base/log";
import type { EnteFile } from "ente-media/file";
import { fileCreationTime } from "ente-media/file-metadata";
import { randomSample } from "ente-utils/array";
-import { savedHiddenCollections } from "../collection";
-import { savedCollectionFiles } from "../photos-fdb";
+import { savedNormalCollectionFiles } from "../file";
import {
savedCGroups,
updateOrCreateUserEntities,
@@ -214,7 +213,8 @@ export interface PeopleState {
* construct an in-memory list of {@link Person}s on which the UI will operate.
*/
export const reconstructPeopleState = async (): Promise<PeopleState> => {
- const fileByID = await savedNormalFileByFileID();
+ const normalCollectionFiles = await savedNormalCollectionFiles();
+ const fileByID = new Map(normalCollectionFiles.map((f) => [f.id, f]));
// "Person face"s are faces annotated with their corresponding local files.
//
@@ -379,22 +379,6 @@ export const reconstructPeopleState = async (): Promise<PeopleState> => {
return { people, visiblePeople, personByFaceID };
};
-/**
- * Read the saved data directly from files DB, and construct a map from fileID
- * to file for all normal (non-hidden) files.
- */
-const savedNormalFileByFileID = async () => {
- const hiddenCollections = await savedHiddenCollections();
- const hiddenCollectionIDs = new Set(hiddenCollections.map((c) => c.id));
-
- const collectionFiles = await savedCollectionFiles();
- const normalCollectionFiles = collectionFiles.filter(
- (f) => !hiddenCollectionIDs.has(f.collectionID),
- );
-
- return new Map(normalCollectionFiles.map((f) => [f.id, f]));
-};
-
/**
* Older versions of the mobile app set the avatarFileID as the avatarFaceID.
* Use the format of the string to detect such cases, and as a workaround,
@@ -535,8 +519,8 @@ export const _suggestionsAndChoicesForPerson = async (
// Annotate the clusters with the information that the UI needs to show its
// preview faces.
-
- const fileByID = await savedNormalFileByFileID();
+ const normalCollectionFiles = await savedNormalCollectionFiles();
+ const fileByID = new Map(normalCollectionFiles.map((f) => [f.id, f]));
const toPreviewable = (cluster: FaceCluster) => {
const previewFaces: PreviewableFace[] = [];
diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.ts
index 0b21ecb389..8e06024b1a 100644
--- a/web/packages/new/photos/services/ml/worker.ts
+++ b/web/packages/new/photos/services/ml/worker.ts
@@ -8,9 +8,9 @@ import type { ElectronMLWorker } from "ente-base/types/ipc";
import { isNetworkDownloadError } from "ente-gallery/services/download";
import type { ProcessableUploadItem } from "ente-gallery/services/upload";
import { fileLogID, type EnteFile } from "ente-media/file";
-import { getLocalTrashFileIDs } from "ente-new/photos/services/trash";
+import { savedTrashItemFileIDs } from "ente-new/photos/services/trash";
import { wait } from "ente-utils/promise";
-import { savedFiles } from "../photos-fdb";
+import { savedCollectionFiles } from "../photos-fdb";
import {
createImageBitmapAndData,
fetchRenderableBlob,
@@ -30,8 +30,8 @@ import {
} from "./cluster";
import { saveFaceCrops } from "./crop";
import {
- getIndexableFileIDs,
markIndexingFailed,
+ readNextIndexableFileIDs,
savedFaceIndexes,
saveIndexes,
updateAssumingLocalFiles,
@@ -324,7 +324,7 @@ export class MLWorker {
async clusterFaces(masterKey: string) {
const { clusters, modifiedClusterIDs } = await _clusterFaces(
await savedFaceIndexes(),
- await savedFiles(),
+ await savedCollectionFiles(),
(progress) => this.updateClusteringProgress(progress),
);
await reconcileClusters(clusters, modifiedClusterIDs, masterKey);
@@ -436,16 +436,16 @@ const indexNextBatch = async (
const syncWithLocalFilesAndGetFilesToIndex = async (
count: number,
): Promise<Map<number, EnteFile>> => {
- const localFiles = await savedFiles();
- const localFileByID = new Map(localFiles.map((f) => [f.id, f]));
+ const collectionFiles = await savedCollectionFiles();
+ const fileByID = new Map(collectionFiles.map((f) => [f.id, f]));
await updateAssumingLocalFiles(
- Array.from(localFileByID.keys()),
- await getLocalTrashFileIDs(),
+ Array.from(fileByID.keys()),
+ await savedTrashItemFileIDs(),
);
- const fileIDsToIndex = await getIndexableFileIDs(count);
- return new Map(fileIDsToIndex.map((id) => [id, localFileByID.get(id)!]));
+ const fileIDsToIndex = await readNextIndexableFileIDs(count);
+ return new Map(fileIDsToIndex.map((id) => [id, fileByID.get(id)!]));
};
/**
diff --git a/web/packages/new/photos/services/trash.ts b/web/packages/new/photos/services/trash.ts
index 9afc472be7..af880d9b2a 100644
--- a/web/packages/new/photos/services/trash.ts
+++ b/web/packages/new/photos/services/trash.ts
@@ -240,7 +240,7 @@ export const sortTrashItems = (trashItems: TrashItem[]) =>
* Return the IDs of all the files that are part of the trash in our local
* database.
*/
-export const getLocalTrashFileIDs = () =>
+export const savedTrashItemFileIDs = () =>
savedTrashItems().then((items) => new Set(items.map((f) => f.file.id)));
/**