From 82b68802b8eac588dc203d02fcbe64e4ea6a88ac Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Sat, 21 Dec 2024 12:00:47 -0800 Subject: [PATCH] Preserve timestamps --- api/routes/import.ts | 24 +++++++++++++++++++----- api/routes/loadout-share.ts | 2 +- api/routes/update.ts | 9 +++++---- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/api/routes/import.ts b/api/routes/import.ts index 885794f..7b1faee 100644 --- a/api/routes/import.ts +++ b/api/routes/import.ts @@ -231,16 +231,22 @@ export async function statelyImport( triumphs: ExportResponse['triumphs'], searches: ExportResponse['searches'], itemHashTags: ItemHashTag[], + deleteExisting = true, ): Promise { // TODO: what we should do, is map all these to items, and then we can just do // batch puts, 25 at a time. let numTriumphs = 0; - await deleteAllDataForUser(bungieMembershipId, platformMembershipIds); + if (deleteExisting) { + await deleteAllDataForUser(bungieMembershipId, platformMembershipIds); + } + + const settingsItem = convertToStatelyItem( + { ...defaultSettings, ...settings }, + bungieMembershipId, + ); - const items: AnyItem[] = [ - convertToStatelyItem({ ...defaultSettings, ...settings }, bungieMembershipId), - ]; + const items: AnyItem[] = []; items.push(...importLoadouts(loadouts)); items.push(...importTags(itemAnnotations)); for (const platformMembershipId of platformMembershipIds) { @@ -262,9 +268,17 @@ export async function statelyImport( items.push(...importSearches(platformMembershipId, searches)); } + // Put the settings in first since it's in a different group + await client.put({ + item: settingsItem, + mustNotExist: true, + }); // OK now put them in as fast as we can for (const batch of batches(items)) { - await client.putBatch(...batch); + // We shouldn't have any existing items... + await client.putBatch( + ...batch.map((item) => ({ item, mustNotExist: true, overwriteMetadataTimestamps: true })), + ); await delay(100); // give it some time to flush } diff --git a/api/routes/loadout-share.ts b/api/routes/loadout-share.ts index c3d274d..b684cff 100644 --- a/api/routes/loadout-share.ts +++ b/api/routes/loadout-share.ts @@ -54,7 +54,7 @@ export const loadoutShareHandler = asyncHandler(async (req, res) => { }); } - const validationResult = validateLoadout('loadout_share', loadout, appId); + const validationResult = validateLoadout('loadout_share', loadout); if (validationResult) { res.status(400).send(validationResult); return; diff --git a/api/routes/update.ts b/api/routes/update.ts index 99edac2..911b574 100644 --- a/api/routes/update.ts +++ b/api/routes/update.ts @@ -154,6 +154,7 @@ export const updateHandler = asyncHandler(async (req, res) => { triumphs, searches, itemHashTags, + !migrationState.lastError, ); }; @@ -232,7 +233,7 @@ function validateUpdates( break; case 'loadout': - result = validateUpdateLoadout(update.payload, appId); + result = validateUpdateLoadout(update.payload); break; case 'tag': @@ -514,11 +515,11 @@ async function updateLoadout( metrics.timing('update.loadout', start); } -function validateUpdateLoadout(loadout: Loadout, appId: string): ProfileUpdateResult { - return validateLoadout('update', loadout, appId) ?? { status: 'Success' }; +function validateUpdateLoadout(loadout: Loadout): ProfileUpdateResult { + return validateLoadout('update', loadout) ?? { status: 'Success' }; } -export function validateLoadout(metricPrefix: string, loadout: Loadout, appId: string) { +export function validateLoadout(metricPrefix: string, loadout: Loadout) { if (!loadout.name) { metrics.increment(`${metricPrefix}.validation.loadoutNameMissing.count`); return {