Skip to content

armgit / ente

Public Imported from GitHub
0

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

Conv

Manav Rathi3f0897ae776f
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 5edfb77f6c..6ac6e94c99 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -73,13 +73,14 @@ import {
areOnlySystemCollections,
PseudoCollectionID,
} from "ente-new/photos/services/collection-summary";
-import { getAllLocalCollections } from "ente-new/photos/services/collections";
import exportService from "ente-new/photos/services/export";
import { updateFilesVisibility } from "ente-new/photos/services/file";
+import { getLocalTrashedFiles } from "ente-new/photos/services/files";
import {
- getLocalFiles,
- getLocalTrashedFiles,
-} from "ente-new/photos/services/files";
+ savedCollections,
+ savedHiddenFiles,
+ savedNormalFiles,
+} from "ente-new/photos/services/photos-fdb";
import {
filterSearchableFiles,
setSearchCollectionsAndFiles,
@@ -328,9 +329,9 @@ const Page: React.FC = () => {
type: "mount",
user,
familyData,
- collections: await getAllLocalCollections(),
- normalFiles: await getLocalFiles("normal"),
- hiddenFiles: await getLocalFiles("hidden"),
+ collections: await savedCollections(),
+ normalFiles: await savedNormalFiles(),
+ hiddenFiles: await savedHiddenFiles(),
trashedFiles: await getLocalTrashedFiles(),
});
await syncWithRemote({ force: true });
diff --git a/web/apps/photos/src/utils/collection.ts b/web/apps/photos/src/utils/collection.ts
index 628cc9f095..1284041311 100644
--- a/web/apps/photos/src/utils/collection.ts
+++ b/web/apps/photos/src/utils/collection.ts
@@ -15,14 +15,12 @@ import {
restoreToCollection,
} from "ente-new/photos/services/collection";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
+import { getLocalCollections } from "ente-new/photos/services/collections";
+import { getLocalFiles } from "ente-new/photos/services/files";
import {
- getAllLocalCollections,
- getLocalCollections,
-} from "ente-new/photos/services/collections";
-import {
- getAllLocalFiles,
- getLocalFiles,
-} from "ente-new/photos/services/files";
+ savedCollections,
+ savedFiles,
+} from "ente-new/photos/services/photos-fdb";
import { safeDirectoryName } from "ente-new/photos/utils/native-fs";
import { getData } from "ente-shared/storage/localStorage";
import {
@@ -78,13 +76,13 @@ export async function downloadCollectionHelper(
setFilesDownloadProgressAttributes: SetFilesDownloadProgressAttributes,
) {
try {
- const allFiles = await getAllLocalFiles();
+ const allFiles = await savedFiles();
const collectionFiles = allFiles.filter(
- (file) => file.collectionID === collectionID,
+ (file) => file.collectionID == collectionID,
);
- const allCollections = await getAllLocalCollections();
+ const allCollections = await savedCollections();
const collection = allCollections.find(
- (collection) => collection.id === collectionID,
+ (collection) => collection.id == collectionID,
);
if (!collection) {
throw Error("collection not found");
diff --git a/web/apps/photos/tests/upload.test.ts b/web/apps/photos/tests/upload.test.ts
index 3a23563197..543438249b 100644
--- a/web/apps/photos/tests/upload.test.ts
+++ b/web/apps/photos/tests/upload.test.ts
@@ -10,10 +10,8 @@ import {
import { fileFileName } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
import { getLocalCollections } from "ente-new/photos/services/collections";
-import {
- getLocalFiles,
- groupFilesByCollectionID,
-} from "ente-new/photos/services/files";
+import { groupFilesByCollectionID } from "ente-new/photos/services/files";
+import { savedNormalFiles } from "ente-new/photos/services/photos-fdb";
import { getUserDetailsV2 } from "ente-new/photos/services/user-details";
const DATE_TIME_PARSING_TEST_FILE_NAMES = [
@@ -189,7 +187,7 @@ async function totalCollectionCountCheck(expectedState) {
}
async function collectionWiseFileCount(expectedState) {
- const files = await getLocalFiles();
+ const files = await savedNormalFiles();
const collections = await getLocalCollections();
const collectionToFilesMap = groupFilesByCollectionID(files);
const collectionIDToNameMap = new Map(
@@ -218,7 +216,7 @@ async function collectionWiseFileCount(expectedState) {
}
async function thumbnailGenerationFailedFilesCheck(expectedState) {
- const files = await getLocalFiles();
+ const files = await savedNormalFiles();
const filesWithStaticThumbnail = files.filter(
(file) => file.metadata.hasStaticThumbnail,
);
@@ -260,7 +258,7 @@ async function thumbnailGenerationFailedFilesCheck(expectedState) {
}
async function livePhotoClubbingCheck(expectedState) {
- const files = await getLocalFiles();
+ const files = await savedNormalFiles();
const livePhotos = files.filter(
(file) => file.metadata.fileType == FileType.livePhoto,
);
@@ -295,7 +293,7 @@ async function livePhotoClubbingCheck(expectedState) {
}
async function exifDataParsingCheck(expectedState) {
- const files = await getLocalFiles();
+ const files = await savedNormalFiles();
Object.entries(expectedState.exif).map(([fileName, exifValues]) => {
const matchingFile = files.find(
(file) => fileFileName(file) == fileName,
@@ -334,7 +332,7 @@ async function exifDataParsingCheck(expectedState) {
}
async function fileDimensionExtractionCheck(expectedState) {
- const files = await getLocalFiles();
+ const files = await savedNormalFiles();
Object.entries(expectedState.file_dimensions).map(
([fileName, dimensions]) => {
const matchingFile = files.find(
@@ -361,7 +359,7 @@ async function fileDimensionExtractionCheck(expectedState) {
}
async function googleMetadataReadingCheck(expectedState) {
- const files = await getLocalFiles();
+ const files = await savedNormalFiles();
Object.entries(expectedState.google_import).map(([fileName, metadata]) => {
const matchingFile = files.find(
(file) => fileFileName(file) == fileName,
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index b5abd7a3ef..b352c5ba20 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -13,10 +13,10 @@ import { fileLogID, type EnteFile } from "ente-media/file";
import { FileType } from "ente-media/file-type";
import { updateFilePublicMagicMetadata } from "ente-new/photos/services/file";
import {
- getAllLocalFiles,
getLocalTrashFileIDs,
uniqueFilesByID,
} from "ente-new/photos/services/files";
+import { savedFiles } from "ente-new/photos/services/photos-fdb";
import { gunzip, gzip } from "ente-new/photos/utils/gzip";
import { randomSample } from "ente-utils/array";
import { ensurePrecondition } from "ente-utils/ensure";
@@ -879,7 +879,7 @@ const processQueue = async () => {
const backfillQueue = async (
userID: number,
): Promise<VideoProcessingQueueItem[]> => {
- const allCollectionFiles = await getAllLocalFiles();
+ const allCollectionFiles = await savedFiles();
const localTrashFileIDs = await getLocalTrashFileIDs();
const videoFiles = uniqueFilesByID(
allCollectionFiles.filter(
diff --git a/web/packages/new/photos/services/collections.ts b/web/packages/new/photos/services/collections.ts
index 56b9157b0d..908fe9effd 100644
--- a/web/packages/new/photos/services/collections.ts
+++ b/web/packages/new/photos/services/collections.ts
@@ -37,15 +37,12 @@ const COLLECTION_UPDATION_TIME = "collection-updation-time";
export const getLocalCollections = async (
type: "normal" | "hidden" = "normal",
): Promise<Collection[]> => {
- const collections = await getAllLocalCollections();
+ const collections = await savedCollections();
return type == "normal"
? collections.filter((c) => !isHiddenCollection(c))
: collections.filter((c) => isHiddenCollection(c));
};
-export const getAllLocalCollections = async (): Promise<Collection[]> =>
- savedCollections();
-
export const getCollectionLastSyncTime = async (collection: Collection) =>
(await localForage.getItem<number>(`${collection.id}-time`)) ?? 0;
@@ -78,7 +75,7 @@ export const getAllLatestCollections = async (): Promise<Collection[]> => {
};
export const syncCollections = async () => {
- const localCollections = await getAllLocalCollections();
+ const localCollections = await savedCollections();
let sinceTime = await getCollectionUpdationTime();
const changes = await getCollectionChanges(sinceTime);
diff --git a/web/packages/new/photos/services/export-migration.ts b/web/packages/new/photos/services/export-migration.ts
index 6d8913b51c..466add9e5a 100644
--- a/web/packages/new/photos/services/export-migration.ts
+++ b/web/packages/new/photos/services/export-migration.ts
@@ -15,7 +15,6 @@ 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 { getAllLocalFiles } from "ente-new/photos/services/files";
import {
safeDirectoryName,
safeFileName,
@@ -33,6 +32,7 @@ import exportService, {
type ExportStage,
type FileExportNames,
} from "./export";
+import { savedFiles } from "./photos-fdb";
type ExportedCollectionPaths = Record<number, string>;
@@ -140,7 +140,7 @@ async function migrationV0ToV1(
}
const collectionIDPathMap = new Map<number, string>();
const user: User = getData("user");
- const localFiles = mergeMetadata(await getAllLocalFiles());
+ const localFiles = mergeMetadata(await savedFiles());
const localCollections = await getLocalCollections();
const personalFiles = getIDBasedSortedFiles(
localFiles.filter((file) => file.ownerID == user.id),
@@ -179,7 +179,7 @@ async function migrationV2ToV3(
return;
}
const user: User = getData("user");
- const localFiles = mergeMetadata(await getAllLocalFiles());
+ const localFiles = mergeMetadata(await savedFiles());
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 7ffaccc25f..fa8b1f0ab8 100644
--- a/web/packages/new/photos/services/export.ts
+++ b/web/packages/new/photos/services/export.ts
@@ -23,8 +23,6 @@ import {
collectionUserFacingName,
createCollectionNameByID,
} from "ente-new/photos/services/collection";
-import { getAllLocalCollections } from "ente-new/photos/services/collections";
-import { getAllLocalFiles } from "ente-new/photos/services/files";
import {
safeDirectoryName,
safeFileName,
@@ -34,6 +32,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";
/** Name of the JSON file in which we keep the state of the export. */
const exportRecordFileName = "export_status.json";
@@ -248,11 +247,7 @@ class ExportService {
* happen.
*/
pendingFiles = async (exportRecord?: ExportRecord): Promise<EnteFile[]> => {
- return getUnExportedFiles(
- await getAllLocalFiles(),
- exportRecord,
- undefined,
- );
+ return getUnExportedFiles(await savedFiles(), exportRecord, undefined);
};
async preExport(exportFolder: string) {
@@ -358,8 +353,8 @@ class ExportService {
{ resync }: ExportOpts,
) {
try {
- const files = mergeMetadata(await getAllLocalFiles());
- const collections = await getAllLocalCollections();
+ const files = mergeMetadata(await savedFiles());
+ const collections = await savedCollections();
const exportRecord = await this.getExportRecord(exportFolder);
const collectionIDExportNameMap =
diff --git a/web/packages/new/photos/services/files.ts b/web/packages/new/photos/services/files.ts
index cf67961b2a..e8f4f8159d 100644
--- a/web/packages/new/photos/services/files.ts
+++ b/web/packages/new/photos/services/files.ts
@@ -19,20 +19,12 @@ import {
setCollectionLastSyncTime,
} from "./collections";
import {
- savedFiles,
savedHiddenFiles,
savedNormalFiles,
saveHiddenFiles,
saveNormalFiles,
} from "./photos-fdb";
-/**
- * Return all files that we know about locally, both "normal" and "hidden".
- *
- * Deprecated, use {@link savedFiles} instead.
- */
-export const getAllLocalFiles = savedFiles;
-
/**
* Return all files that we know about locally. By default it returns only
* "normal" (i.e. non-"hidden") files, but it can be passed the {@link type}
diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts
index 6e5cba343b..bd5cb1daad 100644
--- a/web/packages/new/photos/services/ml/people.ts
+++ b/web/packages/new/photos/services/ml/people.ts
@@ -2,7 +2,7 @@ import { assertionFailed } from "ente-base/assert";
import log from "ente-base/log";
import type { EnteFile } from "ente-media/file";
import { randomSample } from "ente-utils/array";
-import { getLocalFiles } from "../files";
+import { savedNormalFiles } from "../photos-fdb";
import {
savedCGroups,
updateOrCreateUserEntities,
@@ -212,7 +212,7 @@ 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 files = await getLocalFiles("normal");
+ const files = await savedNormalFiles();
const fileByID = new Map(files.map((f) => [f.id, f]));
// "Person face"s are faces annotated with their corresponding local files.
@@ -519,7 +519,7 @@ export const _suggestionsAndChoicesForPerson = async (
// Annotate the clusters with the information that the UI needs to show its
// preview faces.
- const files = await getLocalFiles("normal");
+ const files = await savedNormalFiles();
const fileByID = new Map(files.map((f) => [f.id, f]));
const toPreviewable = (cluster: FaceCluster) => {
diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.ts
index c3fb908879..57cc238840 100644
--- a/web/packages/new/photos/services/ml/worker.ts
+++ b/web/packages/new/photos/services/ml/worker.ts
@@ -9,7 +9,8 @@ import { isNetworkDownloadError } from "ente-gallery/services/download";
import type { ProcessableUploadItem } from "ente-gallery/services/upload";
import { fileLogID, type EnteFile } from "ente-media/file";
import { wait } from "ente-utils/promise";
-import { getAllLocalFiles, getLocalTrashFileIDs } from "../files";
+import { getLocalTrashFileIDs } from "../files";
+import { savedFiles } from "../photos-fdb";
import {
createImageBitmapAndData,
fetchRenderableBlob,
@@ -323,7 +324,7 @@ export class MLWorker {
async clusterFaces(masterKey: string) {
const { clusters, modifiedClusterIDs } = await _clusterFaces(
await savedFaceIndexes(),
- await getAllLocalFiles(),
+ await savedFiles(),
(progress) => this.updateClusteringProgress(progress),
);
await reconcileClusters(clusters, modifiedClusterIDs, masterKey);
@@ -435,7 +436,7 @@ const indexNextBatch = async (
const syncWithLocalFilesAndGetFilesToIndex = async (
count: number,
): Promise<Map<number, EnteFile>> => {
- const localFiles = await getAllLocalFiles();
+ const localFiles = await savedFiles();
const localFileByID = new Map(localFiles.map((f) => [f.id, f]));
await updateAssumingLocalFiles(