Skip to content

armgit / ente

Public Imported from GitHub
0

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

impl

Manav Rathia2df4fb48ace
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index 84574821ad..d038942598 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -495,6 +495,33 @@ const syncProcessedFileIDs = async () =>
},
);
+/**
+ * Remove any saved entries for file IDs which were previously in trash but now
+ * have been permanently deleted.
+ *
+ * This is called when processing the trash diff. It gives us a hook to clear
+ * these IDs from our video processing related local state.
+ *
+ * See: [Note: Pruning stale status-diff entries]
+ *
+ * It is a no-op when we're running in the context of the web app (since it
+ * doesn't currently process videos, so doesn't need to keep any local state for
+ * that purpose).
+ */
+export const videoPrunePermanentlyDeletedFileIDsIfNeeded = async (
+ deletedFileIDs: Set<number>,
+) => {
+ if (!isDesktop) return;
+
+ const existing = await savedProcessedVideoFileIDs();
+ if (existing.size > 0) {
+ const updated = existing.difference(deletedFileIDs);
+ if (updated.size != existing.size) {
+ await saveProcessedVideoFileIDs(updated);
+ }
+ }
+};
+
/**
* If video processing is enabled, trigger a sync with remote and any subsequent
* backfill queue processing for pending videos.
diff --git a/web/packages/new/photos/services/collections.ts b/web/packages/new/photos/services/collections.ts
index 50a20d590c..2ee70780a0 100644
--- a/web/packages/new/photos/services/collections.ts
+++ b/web/packages/new/photos/services/collections.ts
@@ -356,16 +356,16 @@ async function getLastTrashSyncTime() {
* callback can be invoked multiple times during the sync (once for each batch
* that gets processed).
*
- * @param onPruneDeletedFiles A callback invoked when files that were previously
- * in trash have now been permanently deleted. This can be used by other
- * subsystems to prune data referring to files that now have been deleted
- * permanently. This callback can be invoked multiple times during the sync
+ * @param onPruneDeletedFileIDs A callback invoked when files that were
+ * previously in trash have now been permanently deleted. This can be used by
+ * other subsystems to prune data referring to files that now have been deleted
+ * permanently. This callback can be invoked multiple times during the sync
* (once for each batch that gets processed).
*/
export async function syncTrash(
collections: Collection[],
- onUpdateTrashFiles: (files: EnteFile[]) => void,
- onPruneDeletedFiles: (files: EnteFile[]) => void,
+ onUpdateTrashFiles: ((files: EnteFile[]) => void) | undefined,
+ onPruneDeletedFileIDs: (deletedFileIDs: Set<number>) => Promise<void>,
): Promise<void> {
const trash = await getLocalTrash();
collections = [...collections, ...(await getLocalDeletedCollections())];
@@ -382,7 +382,7 @@ export async function syncTrash(
trash,
lastSyncTime,
onUpdateTrashFiles,
- onPruneDeletedFiles,
+ onPruneDeletedFileIDs,
);
await cleanTrashCollections(updatedTrash);
}
@@ -391,8 +391,8 @@ const updateTrash = async (
collections: Map<number, Collection>,
currentTrash: Trash,
sinceTime: number,
- onUpdateTrashFiles: (files: EnteFile[]) => void,
- onPruneDeletedFiles: (files: EnteFile[]) => void,
+ onUpdateTrashFiles: ((files: EnteFile[]) => void) | undefined,
+ onPruneDeletedFileIDs: (deletedFileIDs: Set<number>) => Promise<void>,
): Promise<Trash> => {
let updatedTrash: Trash = [...currentTrash];
try {
@@ -409,6 +409,7 @@ const updateTrash = async (
{ sinceTime: time },
{ "X-Auth-Token": token },
);
+ const deletedFileIDs = new Set<number>();
// #Perf: This can be optimized by running the decryption in parallel
for (const trashItem of resp.data.diff as EncryptedTrashItem[]) {
const collectionID = trashItem.file.collectionID;
@@ -420,6 +421,9 @@ const updateTrash = async (
...collections.values(),
]);
}
+ if (trashItem.isDeleted) {
+ deletedFileIDs.add(trashItem.file.id);
+ }
if (!trashItem.isDeleted && !trashItem.isRestored) {
const decryptedFile = await decryptFile(
trashItem.file,
@@ -437,7 +441,10 @@ const updateTrash = async (
time = resp.data.diff.slice(-1)[0].updatedAt;
}
- onUpdateTrashFiles(getTrashedFiles(updatedTrash));
+ onUpdateTrashFiles?.(getTrashedFiles(updatedTrash));
+ if (deletedFileIDs.size > 0) {
+ await onPruneDeletedFileIDs(deletedFileIDs);
+ }
await localForage.setItem(TRASH, updatedTrash);
await localForage.setItem(TRASH_TIME, time);
} while (resp.data.hasMore);
diff --git a/web/packages/new/photos/services/sync.ts b/web/packages/new/photos/services/sync.ts
index 9bcdc6094d..c242b9db5e 100644
--- a/web/packages/new/photos/services/sync.ts
+++ b/web/packages/new/photos/services/sync.ts
@@ -1,5 +1,8 @@
import { resetFileViewerDataSourceOnClose } from "ente-gallery/components/viewer/data-source";
-import { videoProcessingSyncIfNeeded } from "ente-gallery/services/video";
+import {
+ videoProcessingSyncIfNeeded,
+ videoPrunePermanentlyDeletedFileIDsIfNeeded,
+} from "ente-gallery/services/video";
import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import { isHiddenCollection } from "ente-new/photos/services/collection";
@@ -141,7 +144,11 @@ export const syncCollectionAndFiles = async (
opts?.onResetHiddenFiles,
opts?.onFetchHiddenFiles,
);
- await syncTrash(collections, opts?.onResetTrashedFiles);
+ await syncTrash(
+ collections,
+ opts?.onResetTrashedFiles,
+ videoPrunePermanentlyDeletedFileIDsIfNeeded,
+ );
if (didUpdateNormalFiles || didUpdateHiddenFiles) {
// TODO: Ok for now since its is only commented for the deduper (gallery
// does this on the return value), but still needs fixing instead of a