From 2f382cfe481a1cfe6ec6c4335cf73aa0ab1457be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Fri, 5 Jan 2024 11:56:08 +0100 Subject: [PATCH] feat(backup): Remove old dedup mechanism --- .../domain/backup/services/manageBackup.ts | 8 +- .../services/manageLocalBackupConfig.spec.ts | 82 ------------------- .../services/manageLocalBackupConfig.ts | 25 ------ .../services/manageRemoteBackupConfig.ts | 12 +-- 4 files changed, 3 insertions(+), 124 deletions(-) delete mode 100644 src/app/domain/backup/services/manageLocalBackupConfig.spec.ts diff --git a/src/app/domain/backup/services/manageBackup.ts b/src/app/domain/backup/services/manageBackup.ts index bf86209d5..881bc55ff 100644 --- a/src/app/domain/backup/services/manageBackup.ts +++ b/src/app/domain/backup/services/manageBackup.ts @@ -10,8 +10,7 @@ import { setBackupAsRunning, setBackupAsDone, setLastBackup, - fixLocalBackupConfigIfNecessary, - addRemoteDuplicatesToBackupedMedias + fixLocalBackupConfigIfNecessary } from '/app/domain/backup/services/manageLocalBackupConfig' import { prepareDeduplication } from '/app/domain/backup/services/manageRemoteBackupConfig' import { getMediasToBackup } from '/app/domain/backup/services/getMedias' @@ -260,10 +259,5 @@ const initializeBackup = async ( throw e } - if (flag('flagship.backup.dedup')) { - await addRemoteDuplicatesToBackupedMedias(client) - localBackupConfig = await getLocalBackupConfig(client) - } - return localBackupConfig } diff --git a/src/app/domain/backup/services/manageLocalBackupConfig.spec.ts b/src/app/domain/backup/services/manageLocalBackupConfig.spec.ts deleted file mode 100644 index cdf467f4f..000000000 --- a/src/app/domain/backup/services/manageLocalBackupConfig.spec.ts +++ /dev/null @@ -1,82 +0,0 @@ -import * as manageRemoteBackupConfig from '/app/domain/backup/services/manageRemoteBackupConfig' -import * as manageLocalBackupConfig from '/app/domain/backup/services/manageLocalBackupConfig' -import { LocalBackupConfig } from '/app/domain/backup/models' - -import type CozyClient from 'cozy-client' - -const IMG_0001 = { - creationDate: 1299975445000, - md5: 'Y0VRfq0vJ3b2gOxZjk31WQ==', - modificationDate: 1441224147000, - name: 'IMG_0001.JPG', - remoteId: 'c3843c5245f8a47c56a185d13f8483c6', - uri: 'ph://106E99A1-4F6A-45A2-B320-B0AD4A8E8473/L0/001' -} - -const IMG_0002 = { - creationDate: 1255122560000, - md5: 'LcGi/CqoM7ALktxDiKhhOQ==', - modificationDate: 1441224147000, - name: 'IMG_0002.JPG', - remoteId: 'c3843c5245f8a47c56a185d13f848d27', - uri: 'ph://B84E8479-475C-4727-A4A4-B77AA9980897/L0/001' -} - -describe('addRemoteDuplicatesToBackupedMedias', () => { - test('should merge previous backuped medias with new remote duplicates found', async () => { - // Given - jest - .spyOn(manageLocalBackupConfig, 'getLocalBackupConfig') - .mockResolvedValue( - Promise.resolve({ - backupedMedias: [IMG_0001] - } as LocalBackupConfig) - ) - - jest - .spyOn(manageRemoteBackupConfig, 'fetchBackupedMedias') - .mockResolvedValue(Promise.resolve([IMG_0002])) - - const setLocalBackupConfigMock = jest - .spyOn(manageLocalBackupConfig, 'setLocalBackupConfig') - .mockResolvedValue(Promise.resolve()) - - // When - await manageLocalBackupConfig.addRemoteDuplicatesToBackupedMedias( - {} as CozyClient - ) - - const newLocalBackupConfig = setLocalBackupConfigMock.mock.calls[0][1] - - // Then - expect(newLocalBackupConfig.backupedMedias.length).toBe(2) - }) - - test('should not create duplicates in backuped media list when remote duplicate is already in backuped media list', async () => { - // Given - jest - .spyOn(manageLocalBackupConfig, 'getLocalBackupConfig') - .mockResolvedValue( - Promise.resolve({ - backupedMedias: [IMG_0001] - } as LocalBackupConfig) - ) - - jest - .spyOn(manageRemoteBackupConfig, 'fetchBackupedMedias') - .mockResolvedValue(Promise.resolve([IMG_0001])) - - const setLocalBackupConfigMock = jest - .spyOn(manageLocalBackupConfig, 'setLocalBackupConfig') - .mockResolvedValue(Promise.resolve()) - - // When - await manageLocalBackupConfig.addRemoteDuplicatesToBackupedMedias( - {} as CozyClient - ) - const newLocalStorage = setLocalBackupConfigMock.mock.calls[0][1] - - // Then - expect(newLocalStorage.backupedMedias.length).toBe(1) - }) -}) diff --git a/src/app/domain/backup/services/manageLocalBackupConfig.ts b/src/app/domain/backup/services/manageLocalBackupConfig.ts index 90d012cc7..e06993e17 100644 --- a/src/app/domain/backup/services/manageLocalBackupConfig.ts +++ b/src/app/domain/backup/services/manageLocalBackupConfig.ts @@ -317,28 +317,3 @@ export const setLastBackup = async ( log.debug('Last backup set') } - -export const addRemoteDuplicatesToBackupedMedias = async ( - client: CozyClient -): Promise => { - log.debug('Trying to find remote duplicates') - - const localBackupConfig = await getLocalBackupConfig(client) - - const remoteDuplicates = await fetchBackupedMedias(client) - - const remoteDuplicatesNotAlreadyConsideredAsBackuped = - remoteDuplicates.filter( - m => !localBackupConfig.backupedMedias.find(a => isSameMedia(a, m)) - ) - - log.debug( - `${remoteDuplicatesNotAlreadyConsideredAsBackuped.length} medias found remotely that are present locally but not in local backuped medias` - ) - - localBackupConfig.backupedMedias = localBackupConfig.backupedMedias.concat( - remoteDuplicatesNotAlreadyConsideredAsBackuped - ) - - await setLocalBackupConfig(client, localBackupConfig) -} diff --git a/src/app/domain/backup/services/manageRemoteBackupConfig.ts b/src/app/domain/backup/services/manageRemoteBackupConfig.ts index f3b0daf28..6062bbb6e 100644 --- a/src/app/domain/backup/services/manageRemoteBackupConfig.ts +++ b/src/app/domain/backup/services/manageRemoteBackupConfig.ts @@ -372,17 +372,9 @@ export const fetchBackupedMedias = async ( const allMedias = await getAllMedias(client) - let data + const filesQuery = buildFilesQuery(deviceId) - if (flag('flagship.backup.dedup')) { - const filesQuery = buildAllMediasFilesQuery() - - data = (await client.queryAll(filesQuery)) as FilesQueryAllResult - } else { - const filesQuery = buildFilesQuery(deviceId) - - data = (await client.queryAll(filesQuery)) as FilesQueryAllResult - } + const data = (await client.queryAll(filesQuery)) as FilesQueryAllResult const backupedMedias = filterMediasAlreadyBackuped(allMedias, data)