Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Prevents N+1 queries, oversized IN clauses and unbounded recursion in database and remote service calls.
Use this skill ↓59% 77%+18 ptsof test cases passed
Passed 17 of 22 test cases with the skill, and 13 of 22 without it.
When splitting large ID collections for batch SQL IN queries, what is the mandatory project-wide default batch size threshold?
Sets the maximum batch size threshold constant to 500.
3 of 3 safety checks passed
当代码涉及数据库或远程服务的批量查询时,防止 N+1、IN 子句过长、递归无界等高频性能陷阱。
与
cc-multi-tenant-safety配合:本 skill 关注「查询效率」,租户隔离遵循后者。
场景: for / stream / forEach 内部直接调用 repo.findById(...) 或同等单条远程调用
每次循环触发一次 SQL/HTTP,N 个元素就是 N 次往返。100 元素 = 100 次 SQL,1000 元素就是 1000 次。本地开发数据少看不出来,生产环境直接拖垮接口。
只要在 service / handler 方法里看到以下任一模式,立即怀疑 N+1:
// ❌ 模式 1:显式 for
for (Order o : orders) {
User u = userRepository.findById(o.getUserId()).orElse(null);
}
// ❌ 模式 2:stream 链
orders.stream()
.map(o -> userRepository.findById(o.getUserId()))
.collect(...);
// ❌ 模式 3:辅助方法被循环调用
for (Item i : items) {
enrichItem(i); // 里面又 findById 一次
}
// ❌ 模式 4:嵌套调用
List<X> list = repoA.findByY(y);
for (X x : list) {
x.setZ(repoB.findById(x.getZId()).orElse(null));
Published skills whose descriptions closely match this one, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.