Optimise getLinkDocuments

This commit is contained in:
Sam Rose 2023-12-18 09:20:44 +00:00
parent 40af0ef31b
commit c5fa0806c8
No known key found for this signature in database
1 changed files with 3 additions and 3 deletions

View File

@ -56,7 +56,7 @@ export async function getLinkDocuments(args: {
try {
let linkRows = (await db.query(getQueryIndex(ViewName.LINK), params)).rows
// filter to get unique entries
const foundIds: string[] = []
const foundIds = new Set()
linkRows = linkRows.filter(link => {
// make sure anything unique is the correct key
if (
@ -65,9 +65,9 @@ export async function getLinkDocuments(args: {
) {
return false
}
const unique = foundIds.indexOf(link.id) === -1
const unique = !foundIds.has(link.id)
if (unique) {
foundIds.push(link.id)
foundIds.add(link.id)
}
return unique
})