From 598ab03fd070f4c9e2569abbe439d983bff79746 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 14 Dec 2023 10:40:22 +0000 Subject: [PATCH] Optimise getUniqueByProp --- packages/server/src/db/linkedRows/linkUtils.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/server/src/db/linkedRows/linkUtils.ts b/packages/server/src/db/linkedRows/linkUtils.ts index 5942e7e5a1..0d2e99fc6c 100644 --- a/packages/server/src/db/linkedRows/linkUtils.ts +++ b/packages/server/src/db/linkedRows/linkUtils.ts @@ -99,9 +99,15 @@ export async function getLinkDocuments(args: { } export function getUniqueByProp(array: any[], prop: string) { - return array.filter((obj, pos, arr) => { - return arr.map(mapObj => mapObj[prop]).indexOf(obj[prop]) === pos - }) + const seen = new Set() + const ret = [] + for (const item of array) { + if (!seen.has(item[prop])) { + seen.add(item[prop]) + ret.push(item) + } + } + return ret } export function getLinkedTableIDs(table: Table): string[] {