Skip to content

Commit

Permalink
Loop cursor rather than memory loading results
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Mar 15, 2024
1 parent 4db888a commit 401f2be
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions sci-log-db/src/repositories/paragraph.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ export class ParagraphRepository extends SnippetRepositoryMixin<
htmlTextcontent: null,
textcontent: {$ne: null},
});
const paragraphs = await paragraphsCursor.toArray();
const baseSnippetRepository = await this.baseSnippetRepository();
await Promise.all(
paragraphs.map(async (paragraph: {_id: string; textcontent: string}) => {
const sanitised = sanitizeTextContent(paragraph.textcontent);
if (!sanitised) return;
return baseSnippetRepository.updateById(
`${paragraph._id}`,
{htmlTextcontent: sanitised},
{currentUser: {roles: ['admin']}},
);
}),
);
for await (const paragraph of paragraphsCursor) {
const sanitised = sanitizeTextContent(paragraph.textcontent);
if (!sanitised) return;
await baseSnippetRepository.updateById(
`${paragraph._id}`,
{htmlTextcontent: sanitised},
{currentUser: {roles: ['admin']}},
);
}
await paragraphsCursor.close();
}
}

0 comments on commit 401f2be

Please sign in to comment.