Skip to content

armgit / ente

Public Imported from GitHub
0

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

Reduce

Manav Rathi926b5de6cdf3
diff --git a/web/packages/new/photos/pages/duplicates.tsx b/web/packages/new/photos/pages/duplicates.tsx
index c5ebbd681a..b4e36be8cc 100644
--- a/web/packages/new/photos/pages/duplicates.tsx
+++ b/web/packages/new/photos/pages/duplicates.tsx
@@ -1,6 +1,5 @@
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
import { pt } from "@/base/i18n";
-import type { EnteFile } from "@/media/file";
import { VerticallyCentered } from "@ente/shared/components/Container";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import MoreHorizIcon from "@mui/icons-material/MoreHoriz";
@@ -8,6 +7,7 @@ import SortIcon from "@mui/icons-material/Sort";
import { Box, IconButton, Stack, Typography } from "@mui/material";
import { useRouter } from "next/router";
import React, { useEffect } from "react";
+import type { DuplicateGroup } from "../services/dedup";
import { useAppContext } from "../types/context";
const Page: React.FC = () => {
@@ -27,57 +27,14 @@ const Page: React.FC = () => {
export default Page;
-/**
- * A group of duplicates as shown in the UI.
- */
-interface DuplicateGroup {
- /**
- * Files which our algorithm has determined to be duplicates of each other.
- *
- * These are sorted in the order of precedence, such that the first item is
- * the one we'd wish to retain if the user decides to dedup this group.
- */
- items: {
- /** The underlying collection file. */
- file: EnteFile;
- /** The name of the collection to which this file belongs. */
- collectionName: string;
- }[];
- /**
- * The size (in bytes) of each item in the group.
- */
- itemSize: number;
- /**
- * The number of files that will be pruned if the user decides to dedup this group.
- */
- prunableCount: number;
- /**
- * The size (in bytes) that can be saved if the user decides to dedup this group.
- */
- prunableSize: number;
- /**
- * `true` if the user has marked this group for deduping.
- */
- isSelected: boolean;
-}
-
interface DuplicatesState {
status: "analyzing" | "deleting" | undefined;
/**
* Groups of duplicates.
*
- * Within each group, the files are sorted in the order of precedence such
- * that the first item is the one we'd wish to retain if the user decides to
- * dedup this group.
- *
- * This is the primary source of truth computed after we exit the
- * "analyzing" state. It is used to derive the {@link duplicateGroups}
- * property which the UI then displays.
- */
- duplicates: EnteFile[][];
- /**
- * {@link duplicates} augmented with UI state and various cached properties
- * to make them more amenable to be directly used by the UI component.
+ * These are groups of files that our algorithm has detected as exact
+ * duplicates, augmented with UI state and various cached properties to make
+ * them more amenable to be directly used by the UI component.
*
* These are sorted in order of display, reflecting the {@link sortType}
* user preference.
diff --git a/web/packages/new/photos/services/dedup.ts b/web/packages/new/photos/services/dedup.ts
index 7b1b79163a..8fb1fb9c32 100644
--- a/web/packages/new/photos/services/dedup.ts
+++ b/web/packages/new/photos/services/dedup.ts
@@ -1,6 +1,67 @@
+import type { EnteFile } from "@/media/file";
+
+/**
+ * A group of duplicates as shown in the UI.
+ */
+export interface DuplicateGroup {
+ /**
+ * Files which our algorithm has determined to be duplicates of each other.
+ *
+ * These are sorted by the collectionName.
+ */
+ items: {
+ /** The underlying collection file. */
+ file: EnteFile;
+ /** The name of the collection to which this file belongs. */
+ collectionName: string;
+ }[];
+ /**
+ * The size (in bytes) of each item in the group.
+ */
+ itemSize: number;
+ /**
+ * The number of files that will be pruned if the user decides to dedup this
+ * group.
+ */
+ prunableCount: number;
+ /**
+ * The size (in bytes) that can be saved if the user decides to dedup this
+ * group.
+ */
+ prunableSize: number;
+ /**
+ * `true` if the user has marked this group for deduping.
+ */
+ isSelected: boolean;
+}
+
/**
* Find exact duplicates in the user's library, and return them in groups that
* can then be deduped keeping only one entry in each group.
+ *
+ * [Note: Deduplication logic]
+ *
+ * Detecting duplicates:
+ *
+ * 1. Identify and divide files into multiple groups based on (size + hash).
+ *
+ * 2. By default select all group, with option to unselect individual groups or
+ * all groups.
+ *
+ * Pruning duplicates:
+ *
+ * When user presses the dedup button with some selected groups,
+ *
+ * 1. Identify and select the file which we don't want to delete (preferring
+ * file with caption or edited time).
+ *
+ * 2. For the remaining files identify the collection owned by the user in which
+ * the remaining files are present.
+ *
+ * 3. Add the file that we don't plan to delete to such collections as a
+ * symlink.
+ *
+ * 4. Delete the remaining files.
*/
export const deduceDuplicates = () => {
return [];