From 98c1d3a5a017df3a16cd19b27e6217cbb8f8ccb4 Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Wed, 27 Sep 2023 09:44:32 +0200 Subject: [PATCH] fix(dashboard): perf on merged items --- dashboard/src/components/DataLoader.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dashboard/src/components/DataLoader.js b/dashboard/src/components/DataLoader.js index b3a3b2d241..be1bfb5884 100644 --- a/dashboard/src/components/DataLoader.js +++ b/dashboard/src/components/DataLoader.js @@ -468,8 +468,11 @@ export function useDataLoader(options = { refreshOnMount: false }) { } export const mergeItems = (oldItems, newItems = []) => { - const newItemsIds = newItems?.map((i) => i._id) || []; - const oldItemsPurged = oldItems.filter((i) => !newItemsIds.includes(i._id)); + const newItemIds = {}; + for (const newItem of newItems) { + newItemIds[newItem._id] = true; + } + const oldItemsPurged = oldItems.filter((i) => !newItemIds[i._id]); return [...oldItemsPurged, ...newItems].filter((e) => !e.deletedAt); };