fix(search): submit documents in batches
This commit is contained in:
parent
d3aee4b41f
commit
ba020c874b
1 changed files with 14 additions and 8 deletions
|
@ -27,14 +27,20 @@ import { prisma } from './db';
|
|||
|
||||
const index = meilisearch.index('comic_pages');
|
||||
|
||||
const batchSize = 100;
|
||||
for (let i = 0; i < Math.ceil(pages.length / batchSize); i++) {
|
||||
const startIndex = i * 100;
|
||||
const endIndex = Math.min(pages.length, (i + 1) * 100);
|
||||
await index.addDocuments(
|
||||
pages.map((page) => {
|
||||
pages.slice(startIndex, endIndex).map((page) => {
|
||||
return {
|
||||
...page,
|
||||
id: `${page.comic.id}-${page.id}`,
|
||||
};
|
||||
})
|
||||
);
|
||||
console.log('submitted', endIndex - startIndex, 'pages in batch no.', i);
|
||||
}
|
||||
|
||||
console.log('submitted', pages.length, 'pages to be indexed');
|
||||
|
||||
|
|
Loading…
Reference in a new issue