IK
Interview Knowledge Book
Темы
Практика
Примеры
Песочница
EN
browser
N+1 query batching
Сравните number of lookups in per-row fetching и batched lookup.
index.js
const posts = [{ authorId: 1 }, { authorId: 2 }, { authorId: 1 }]; const perRowQueries = 1 + posts.length; const uniqueAuthorIds = new Set(posts.map((post) => post.authorId)); const batchedQueries = 1 + 1; console.log('n+1 queries', perRowQueries); console.log('batched queries', batchedQueries); console.log('authors fetched', uniqueAuthorIds.size);
Запустить
Остановить
Сбросить