From 373540a996de6223f0aa6a5fa2e1b9ca7d25b3ea Mon Sep 17 00:00:00 2001 From: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com> Date: Tue, 16 Jul 2024 09:31:49 -0700 Subject: [PATCH] Drop deleted story distribution lists after 30d --- ts/services/storage.ts | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/ts/services/storage.ts b/ts/services/storage.ts index 4a47dc6aee..dc54eef04c 100644 --- a/ts/services/storage.ts +++ b/ts/services/storage.ts @@ -40,7 +40,7 @@ import * as durations from '../util/durations'; import { BackOff } from '../util/BackOff'; import { storageJobQueue } from '../util/JobQueue'; import { sleep } from '../util/sleep'; -import { isMoreRecentThan } from '../util/timestamp'; +import { isMoreRecentThan, isOlderThan } from '../util/timestamp'; import { map, filter } from '../util/iterables'; import { ourProfileKeyService } from './ourProfileKey'; import { @@ -335,12 +335,35 @@ async function generateManifest( `adding storyDistributionLists=${storyDistributionLists.length}` ); - storyDistributionLists.forEach(storyDistributionList => { + for (const storyDistributionList of storyDistributionLists) { const storageRecord = new Proto.StorageRecord(); storageRecord.storyDistributionList = toStoryDistributionListRecord( storyDistributionList ); + if ( + storyDistributionList.deletedAtTimestamp != null && + isOlderThan(storyDistributionList.deletedAtTimestamp, durations.MONTH) + ) { + const droppedID = storyDistributionList.storageID; + const droppedVersion = storyDistributionList.storageVersion; + if (!droppedID) { + continue; + } + + const recordID = redactStorageID(droppedID, droppedVersion); + + log.warn( + `storageService.generateManifest(${version}): ` + + `dropping storyDistributionList=${recordID} ` + + `due to expired deleted timestamp=${storyDistributionList.deletedAtTimestamp}` + ); + deleteKeys.add(droppedID); + + drop(dataInterface.deleteStoryDistribution(storyDistributionList.id)); + continue; + } + const { isNewItem, storageID } = processStorageRecord({ currentStorageID: storyDistributionList.storageID, currentStorageVersion: storyDistributionList.storageVersion, @@ -359,7 +382,7 @@ async function generateManifest( }); }); } - }); + } log.info( `storageService.upload(${version}): ` + @@ -587,6 +610,17 @@ async function generateManifest( } }); + // Save pending deletes until we have a confirmed upload + await window.storage.put( + 'storage-service-pending-deletes', + // Note: `deleteKeys` already includes the prev value of + // 'storage-service-pending-deletes' + Array.from(deleteKeys, storageID => ({ + storageID, + storageVersion: version, + })) + ); + if (deleteKeys.size !== pendingDeletes.size) { const localDeletes = Array.from(deleteKeys).map(key => redactStorageID(key)