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