fix(search): submit documents in batches

This commit is contained in:
Ashhhleyyy 2022-08-01 21:03:11 +01:00
parent d3aee4b41f
commit ba020c874b
Signed by: ash
GPG key ID: 83B789081A0878FB

View file

@ -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');