fix: reduce affiliate code collisions#6242
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughAffiliate-code provisioning is centralized through availability checks, preparation, and conditional backfilling. User creation and OAuth flows prepare codes before persistence, while retrieval ensures missing codes are assigned. ChangesAffiliate code lifecycle
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CreateUser
participant PrepareAffCode
participant UserInsert
participant UsersTable
CreateUser->>PrepareAffCode: prepare affiliate code
PrepareAffCode->>UsersTable: check generated code availability
UsersTable-->>PrepareAffCode: available code
PrepareAffCode-->>CreateUser: continue creation
CreateUser->>UserInsert: insert prepared user
UserInsert->>UsersTable: persist user and affiliate code
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Important
📝 变更描述 / Description
将新用户推广码从 4 位扩展为 8 位,并在写入前有限次数查询候选码是否已被占用;查询包含软删除记录,兼容已有 4 位推广码。普通注册、OAuth 注册、后台创建用户及旧用户补码统一使用模型层分配逻辑,旧用户补码通过条件更新避免同一用户的并发请求互相覆盖。
数据库唯一索引继续作为最终一致性约束。本次有意不处理“候选码查询完成后、写入前被另一请求抢占”的极端竞态:PostgreSQL 需要保存点恢复失败事务,而 MySQL 与 SQLite 的锁及错误语义不同,跨数据库事务内重试会显著扩大改动范围;该竞态发生时仍返回原始数据库错误,但不会写入重复推广码。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
go test ./model ./controller -count=1go vet ./model ./controllergo test ./model -run 'AffCode' -count=10git diff --checkSummary by CodeRabbit
Improvements
Bug Fixes