Skip to content

armgit / ente

Public Imported from GitHub
0

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

Reword

Manav Rathif59ecdb8d8fe
diff --git a/web/apps/photos/src/services/watch.ts b/web/apps/photos/src/services/watch.ts
index 339ae699da..afb172795f 100644
--- a/web/apps/photos/src/services/watch.ts
+++ b/web/apps/photos/src/services/watch.ts
@@ -38,8 +38,6 @@ class FolderWatcher {
* If the file system directory corresponding to the (root) folder path of a
* folder watch is deleted on disk, we note down that in this queue so that
* we can ignore any file system events that come for it next.
- *
- * TODO: is this really needed? the mappings are pre-checked first.
*/
private deletedFolderPaths: string[] = [];
/** `true` if we are using the uploader. */
@@ -89,12 +87,12 @@ class FolderWatcher {
this.syncWithDisk();
}
- /** `true` if we are currently using the uploader */
+ /** Return `true` if we are currently using the uploader. */
isUploadRunning() {
return this.uploadRunning;
}
- /** `true` if syncing has been temporarily paused */
+ /** Return `true` if syncing has been temporarily paused. */
isSyncPaused() {
return this.isPaused;
}
@@ -501,31 +499,30 @@ class FolderWatcher {
this.eventQueue = this.eventQueue.filter(
(event) => !event.filePath.startsWith(deletedFolderPath),
);
+
return true;
}
private async moveToTrash(syncedFiles: FolderWatch["syncedFiles"]) {
+ const syncedFileForID = new Map<number, FolderWatchSyncedFile>();
+ for (const file of syncedFiles)
+ syncedFileForID.set(file.uploadedFileID, file);
+
const files = await getLocalFiles();
- const toTrashFilesMap = new Map<number, FolderWatchSyncedFile>();
- for (const file of syncedFiles) {
- toTrashFilesMap.set(file.uploadedFileID, file);
- }
const filesToTrash = files.filter((file) => {
- if (toTrashFilesMap.has(file.id)) {
- const fileToTrash = toTrashFilesMap.get(file.id);
- if (fileToTrash.collectionID === file.collectionID) {
- return true;
- }
+ const correspondingSyncedFile = syncedFileForID.get(file.id);
+ if (
+ correspondingSyncedFile &&
+ correspondingSyncedFile.collectionID == file.collectionID
+ ) {
+ return true;
}
+ return false;
});
- const groupFilesByCollectionId =
- groupFilesBasedOnCollectionID(filesToTrash);
-
- for (const [
- collectionID,
- filesToTrash,
- ] of groupFilesByCollectionId.entries()) {
- await removeFromCollection(collectionID, filesToTrash);
+
+ const filesByCollectionID = groupFilesBasedOnCollectionID(filesToTrash);
+ for (const [id, files] of filesByCollectionID.entries()) {
+ await removeFromCollection(id, files);
}
this.requestSyncWithRemote();
diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts
index f65d36bd9f..cc3ddc5e16 100644
--- a/web/apps/photos/src/utils/file/index.ts
+++ b/web/apps/photos/src/utils/file/index.ts
@@ -132,16 +132,16 @@ export async function downloadFile(file: EnteFile) {
}
}
-export function groupFilesBasedOnCollectionID(files: EnteFile[]) {
- const collectionWiseFiles = new Map<number, EnteFile[]>();
+/** Segment the given {@link files} into lists indexed by their collection ID */
+export const groupFilesBasedOnCollectionID = (files: EnteFile[]) => {
+ const result = new Map<number, EnteFile[]>();
for (const file of files) {
- if (!collectionWiseFiles.has(file.collectionID)) {
- collectionWiseFiles.set(file.collectionID, []);
- }
- collectionWiseFiles.get(file.collectionID).push(file);
+ const id = file.collectionID;
+ if (!result.has(id)) result.set(id, []);
+ result.get(id).push(file);
}
- return collectionWiseFiles;
-}
+ return result;
+};
function getSelectedFileIds(selectedFiles: SelectedState) {
const filesIDs: number[] = [];