Repository navigation
core: fix: upsert each user when setting roles in bulk - #1224
Conversation
Use per-UID bulk upserts for batch role assignment and skip empty batches while preserving cache invalidation and autojoin behavior. Fixes hydro-dev#1223 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughFor an empty UID array, Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
Fixes #1223.
The array branch of
DomainModel.setUserRolecurrently usesupdateManywith an$infilter andupsert: true. This does not create a record for each missing UID: partially matching batches leave missing users untouched, while entirely unmatched batches can create a document without a UID and trigger a duplicate-key error.Replace this with a single
bulkWritecontaining anupdateOneupsert for each{ domainId, uid }pair.autojoinbehavior.This PR contains only the model fix; no test code or test data is included.
Validation
Verified with temporary regression tests against MongoDB 8.0:
autojoinenabled and disabled, including preservation of existing join status.set_userswithjoin: truethrough the HTTP handler.The original implementation failed six of the eight regression cases; the fixed implementation passed all eight.
Targeted ESLint and backend TypeScript checks with
--skipLibCheckpassed. Without--skipLibCheck, the type check is blocked by an existing third-party declaration error involving@types/koaandcontent-disposition.Summary by CodeRabbit