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 index = meilisearch.index('comic_pages');
|
||||||
|
|
||||||
await index.addDocuments(
|
const batchSize = 100;
|
||||||
pages.map((page) => {
|
for (let i = 0; i < Math.ceil(pages.length / batchSize); i++) {
|
||||||
return {
|
const startIndex = i * 100;
|
||||||
...page,
|
const endIndex = Math.min(pages.length, (i + 1) * 100);
|
||||||
id: `${page.comic.id}-${page.id}`,
|
await index.addDocuments(
|
||||||
};
|
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');
|
console.log('submitted', pages.length, 'pages to be indexed');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue