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 batch database and service calls.
Use this skill ↓73% 86%+14 ptsof test cases passed
Passed 19 of 22 test cases with the skill, and 16 of 22 without it.
In a multi-tenant Spring Data JPA application, what standard method naming pattern should be used for a repository method that fetches a batch of entities by IDs with tenant isolation?
Names the repository method `findByTenantIdAndIdIn(Long tenantId, Collection<Long> ids)`.
3 of 3 safety checks passed
当代码涉及数据库或远程服务的批量查询时,防止 N+1、IN 子句过长、递归无界等高频性能陷阱。
与
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);
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.