N+1 Query (ARCH8050)
هذا المحتوى غير متوفر بلغتك بعد.
Key kotlin.orm.n-plus-one-query · Severity warning · Category orm
Flags a repository or DAO read (findById, find*, get*, query) executed inside a loop - one query per iteration. A batch/bulk read is the fix, not the defect, and is excepted.
Incorrect
Section titled “Incorrect”for (id in orderIds) { val order = orderRepository.findById(id)}Correct
Section titled “Correct”val orders = orderRepository.findAllById(orderIds)Load the set in one query (findAllById, an IN clause, a join) before the loop.