Skip to content

armgit / ente

Public Imported from GitHub
0

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

size

Manav Rathie5fe3a72559a
diff --git a/web/packages/media/file.ts b/web/packages/media/file.ts
index 4979b7be35..331842b445 100644
--- a/web/packages/media/file.ts
+++ b/web/packages/media/file.ts
@@ -327,4 +327,3 @@ export const mergeMetadata1 = (file: EnteFile): EnteFile => {
*/
export const mergeMetadata = (files: EnteFile[]) =>
files.map((file) => mergeMetadata1(file));
-
diff --git a/web/packages/new/photos/services/dedup.ts b/web/packages/new/photos/services/dedup.ts
index a243096031..4085da9d79 100644
--- a/web/packages/new/photos/services/dedup.ts
+++ b/web/packages/new/photos/services/dedup.ts
@@ -81,11 +81,9 @@ export interface DuplicateGroup {
*/
export const deduceDuplicates = async () => {
// TODO: Ignore non-owned files.
- const collectionFiles = await getLocalFiles();
+ const collectionFiles = await getLocalFiles("normal");
const files = uniqueFilesByID(collectionFiles);
- // TODO: Only do a hash comparison
-
const filesByHash = new Map<string, EnteFile[]>();
for (const file of files) {
const hash = metadataHash(file.metadata);
@@ -104,13 +102,32 @@ export const deduceDuplicates = async () => {
const duplicateGroups: DuplicateGroup[] = [];
- for (const potentialDuplicates of filesByHash.values()) {
- if (potentialDuplicates.length < 2) continue;
- const size = potentialDuplicates[0]?.info?.fileSize;
+ for (const duplicates of filesByHash.values()) {
+ if (duplicates.length < 2) continue;
+
+ // Take the size of any of the items, they should all be the same since
+ // the hashes are the same.
+ //
+ // Note that this is not guaranteed in the case of live photos, since
+ // the hash originates from the image and video contents, but the size
+ // comes from the size of their combined zip, and different clients
+ // might use different zip implementation to arrive at non-exact but
+ // similar sizes. The delta should be minor so we can use any of the
+ // sizes, this is only meant as a rough UI hint anyway.
+ let size = 0;
+ for (const file of duplicates) {
+ if (file.info?.fileSize) {
+ size = file.info.fileSize;
+ break;
+ }
+ }
+
+ // If none of the files marked as duplicates have a size, ignored this
+ // group. This shouldn't really happen in practice, but it can happen in
+ // rare cases (group of duplicates uploaded by ancient version of Ente
+ // which did not attach the file size during uploads).
if (!size) continue;
- const duplicates = potentialDuplicates.filter(
- (file) => file.info?.fileSize == size,
- );
+
const items = duplicates
.map((file) => {
const collectionName = collectionNameByID.get(
@@ -120,6 +137,7 @@ export const deduceDuplicates = async () => {
})
.filter((item) => !!item);
if (items.length < 2) continue;
+
duplicateGroups.push({
id: newID("dg_"),
items,
diff --git a/web/packages/new/photos/services/files.ts b/web/packages/new/photos/services/files.ts
index d01a19f33c..4602eada14 100644
--- a/web/packages/new/photos/services/files.ts
+++ b/web/packages/new/photos/services/files.ts
@@ -175,9 +175,9 @@ export const clearCachedThumbnailsIfChanged = async (
// TODO: Add an extra truthy check the EnteFile type is null safe
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!m1 || !m2) continue;
- // Both files exist, have metadata, but their (appropriate) hashes
- // differ, which indicates that the change was in the file's contents,
- // not the metadata itself, and thus we should refresh the thumbnail.
+ // Both files exist, have metadata, but their hashes differ, which
+ // indicates that the change was in the file's contents, not the
+ // metadata itself, and thus we should refresh the thumbnail.
if (metadataHash(m1) != metadataHash(m2)) {
// This is an infrequent occurrence, so we lazily get the cache.
const thumbnailCache = await blobCache("thumbs");