From e1a3475faa3933f1d5e4a18bd2f0c1b3489f467a Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 23 Apr 2024 20:50:15 +0530 Subject: [PATCH] Shorten chunk --- .../src/services/upload/uploadService.ts | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts index 72d4b6e1f..3a7096830 100644 --- a/web/apps/photos/src/services/upload/uploadService.ts +++ b/web/apps/photos/src/services/upload/uploadService.ts @@ -212,38 +212,26 @@ export const uploader = async ( fileTypeInfo, ); - const matchingExistingFiles = findMatchingExistingFiles( - existingFiles, - metadata, - ); + const matches = findMatchingExistingFiles(existingFiles, metadata); + const anyMatch = matches?.length > 0 ? matches[0] : undefined; - if (matchingExistingFiles?.length) { - const matchingExistingFilesCollectionIDs = - matchingExistingFiles.map((e) => e.collectionID); - - if (matchingExistingFilesCollectionIDs.includes(collection.id)) { - log.info( - `Skipping upload of ${name} since it is already present in the collection`, - ); - const sameCollectionMatchingExistingFile = - matchingExistingFiles.find( - (f) => f.collectionID === collection.id, - ); + if (anyMatch) { + const matchInSameCollection = matches.find( + (f) => f.collectionID == collection.id, + ); + if (matchInSameCollection) { return { fileUploadResult: UPLOAD_RESULT.ALREADY_UPLOADED, - uploadedFile: sameCollectionMatchingExistingFile, + uploadedFile: matchInSameCollection, }; } else { - log.info( - `Symlinking ${name} to existing file in ${matchingExistingFilesCollectionIDs.length} collections`, - ); - // any of the matching file can used to add a symlink - const resultFile = Object.assign({}, matchingExistingFiles[0]); - resultFile.collectionID = collection.id; - await addToCollection(collection, [resultFile]); + // Any of the matching files can be used to add a symlink. + const symlink = Object.assign({}, anyMatch); + symlink.collectionID = collection.id; + await addToCollection(collection, [symlink]); return { fileUploadResult: UPLOAD_RESULT.ADDED_SYMLINK, - uploadedFile: resultFile, + uploadedFile: symlink, }; } }