Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve timestamps #259

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading