[Regression on closed #541] TeamsService.create and updateSplits are back to one SELECT per member to check existence
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 75/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- postgresql, typescript
- Lĩnh vực
- backend, databases, performance, testing
Hướng nghiên cứu
Start in src/teams/teams.service.ts at create and updateSplits, where each member is checked with a separate findOne. Read the related team service spec and inspect how repository queries and transactions are used in both methods. Replace the repeated checks with a shared batched existence check, then add a spec confirming one user query for a multi-member payload and run the team service tests.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Location — src/teams/teams.service.ts:28-35 (create) and src/teams/teams.service.ts:80-87 (updateSplits).
Problem — The per-member existence loop closed as #541 is present again, duplicated verbatim in both methods:
// Verify all member userIds exist
for (const member of dto.members) {
const userExists = await this.userRepo.findOne({
where: { id: member.userId },
});
if (!userExists) {
throw new NotFoundException(`User ${member.userId} not found`);
}
}
Each iteration is an awaited round trip, so the queries are strictly sequential: a 20-member team issues 20 serial SELECT * FROM users WHERE id = $1 LIMIT 1 statements before any write happens. findOne with no select also hydrates the full User row (including payout address and other PII columns) when only the row's existence is needed.
Why it matters — Request latency scales linearly with member count at full network round-trip cost, on a write path that then holds a transaction open. It is also a needless source of partial-failure windows: by the time member 20 is checked, member 1 may already have been deleted, so the FK can still reject the insert (see the non-transactional delete/insert problem in updateSplits). And the same five lines now exist in two places, so the next fix has to be applied twice — exactly how this regressed.
Reproduction / failure path
- Enable
DATABASE_LOGGING=true. POST /teamswith 20 distinct valid memberuserIds.- The log shows 20 separate
usersSELECTs before theteamsINSERT, instead of one. - Same for
PATCH /teams/:id/splitswith 20 members.
Suggested fix
- Replace both loops with one batched query and a set difference:
Note this also reports every missing id at once instead of only the first.const ids = members.map((m) => m.userId); const found = await this.userRepo.find({ where: { id: In(ids) }, select: { id: true } }); const missing = ids.filter((id) => !found.some((u) => u.id === id)); if (missing.length) throw new NotFoundException(`User(s) not found: ${missing.join(', ')}`); - Extract it into one private helper (e.g.
assertMembersExist(members, manager?)) used by bothcreateandupdateSplits, taking an optionalEntityManagerso it can run inside the same transaction as the write. - Add a spec asserting
userRepo.findis called exactly once for a multi-member payload, so a future merge cannot quietly reintroduce the loop.
- Ngôn ngữ chính
- TypeScript
- Star
- 2
- Fork
- 90
- Merge trung bình
- 31 phút
- Pull request đã merge (30 ngày)
- 20
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MergeFi/backend
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của MergeFi/backend
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
zapcooking/frontend#946 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
WiliamRosa/cosmos-semantic-platform#40 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
liberation-data/drivine#733 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
makecindy/cindy#10062 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày