Skip to content

Commit

Permalink
Preserve timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Dec 21, 2024
1 parent 388ce98 commit 82b6880
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
24 changes: 19 additions & 5 deletions api/routes/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,22 @@ export async function statelyImport(
triumphs: ExportResponse['triumphs'],
searches: ExportResponse['searches'],
itemHashTags: ItemHashTag[],
deleteExisting = true,
): Promise<number> {
// 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) {
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion api/routes/loadout-share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions api/routes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const updateHandler = asyncHandler(async (req, res) => {
triumphs,
searches,
itemHashTags,
!migrationState.lastError,
);
};

Expand Down Expand Up @@ -232,7 +233,7 @@ function validateUpdates(
break;

case 'loadout':
result = validateUpdateLoadout(update.payload, appId);
result = validateUpdateLoadout(update.payload);
break;

case 'tag':
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 82b6880

Please sign in to comment.