fix(user): migrate lastReultHashes typo to lastResultHashes safely (@mukundangopalachary)#7830
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a long-standing typo in the user document field used for duplicate-result detection, while keeping backward compatibility with existing MongoDB data.
Changes:
- Add correct
lastResultHashesalongside legacylastReultHashesin the sharedUserSchema. - Update backend write-path to write
lastResultHashesand unsetlastReultHashes. - Update backend read-path to fallback
lastResultHashes ?? lastReultHashes ?? []and exclude both from user response shaping.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/schemas/src/users.ts | Adds lastResultHashes while retaining legacy lastReultHashes for compatibility. |
| backend/src/dal/user.ts | Migrates writes to lastResultHashes and unsets legacy key during updates. |
| backend/src/api/controllers/user.ts | Ensures neither hash field is included in “relevant user info” responses. |
| backend/src/api/controllers/result.ts | Reads from corrected key first, then legacy, for duplicate detection. |
fehmer
left a comment
There was a problem hiding this comment.
hi @mukundangopalachary, thank you for your contribution.
This topic keeps popping up in PRs so I guess we should fix it.
To tackle this without doing an database migration lets do the following:
- move the
lastResultHashesfrom theUserSchematoDBUser. Frontend is not using this property - dal writes to the new property, removing the old one (as you already did)
- add the soft-migration to
UserDal.migrateUser
function migrateUser<
T extends Pick<DBUser, "personalBests" | "lastResultHashes">,
>(user: T): T {
user.personalBests ??= {
time: {},
words: {},
quote: {},
zen: {},
custom: {},
};
if ("lastReultHashes" in user) {
user.lastResultHashes = user.lastReultHashes as string[];
}
return user;
}| addedAt: z.number().int().nonnegative(), | ||
| personalBests: PersonalBestsSchema, | ||
| lastReultHashes: z.array(z.string()).optional(), //TODO: fix typo (it's in the db too) | ||
| lastResultHashes: z.array(z.string()).optional(), |
There was a problem hiding this comment.
lastResultHashes is not used on the frontend. We should just remove it here and move it to the DBUsertype.
| | "nameHistory" | ||
| | "lastNameChange" | ||
| | "_id" | ||
| | "lastReultHashes" //TODO fix typo |
There was a problem hiding this comment.
this is obsolete when we move the property to the DBUser
Description
This PR fixes a typo in the user hashes field used for duplicate-result detection.
Problem:
lastReultHashes.Repro (before this change):
lastReultHashes(typo) instead oflastResultHashes.Approach:
lastResultHashes ?? lastReultHashes ?? []lastResultHashes.lastReultHashesduring updates.Checks
Closes #
Suggested PR title format (per their rule):