Skip to content

fix(user): IsPhone validation and single-field login lookup#129

Merged
tylor-zhang merged 3 commits into
mainfrom
fix/optimize-find-by-login
Jun 16, 2026
Merged

fix(user): IsPhone validation and single-field login lookup#129
tylor-zhang merged 3 commits into
mainfrom
fix/optimize-find-by-login

Conversation

@zzswang

@zzswang zzswang commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • 新增 isPhone / @IsPhone / detectLoginField(正则,无新依赖):支持中国 11 位手机号(含连字符/空格)及 + 开头的国际号
  • UserDoc.phone 及 auth 相关 phone DTO(验证码登录、手机注册、重置密码)写入时校验格式
  • findByLogin 改为判定 login 类型后只查一个字段(email / phone / username),无 fallback,避免错登和 $or 全表扫描

登录判定规则

输入特征 判定 查询
@ email { email }
匹配 phone 正则 phone { phone }
其余 username { username }

Test plan

  • 单元测试:validate.test.spec.tsuser.service.spec.ts 通过
  • 全量 npm test 61 个用例通过
  • 部署后确认 MongoDB 慢查询中 findByLogin 不再出现 COLLSCAN
  • 确认生产库 username / email / phone 索引存在

zzswang and others added 2 commits June 15, 2026 23:15
Replace $or collection scan with prioritized lookups by login format so
phone, email, and username each hit their partial unique indexes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use regex-based phone validation for user writes and auth phone DTOs.
Replace findByLogin $or/fallback with detectLoginField + one indexed query.

Co-authored-by: Cursor <cursoragent@cursor.com>
@zzswang zzswang changed the title fix(user): optimize findByLogin to avoid slow $or collection scan fix(user): IsPhone validation and single-field login lookup Jun 16, 2026
Treat all phone numbers with one pattern: optional +, digits, separators,
and 6-15 digit length.

Co-authored-by: Cursor <cursoragent@cursor.com>
@tylor-zhang tylor-zhang merged commit 772bc56 into main Jun 16, 2026
3 checks passed
@tylor-zhang tylor-zhang deleted the fix/optimize-find-by-login branch June 16, 2026 02:02
tylor-zhang pushed a commit that referenced this pull request Jun 16, 2026
🤖 I have created a release *beep* *boop*
---


## [2.28.1](v2.28.0...v2.28.1)
(2026-06-16)


### Bug Fixes

* **user:** IsPhone validation and single-field login lookup
([#129](#129))
([772bc56](772bc56))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants