From 41fc86c05331fd86b941e75edb20d213017371e2 Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Wed, 27 Sep 2023 09:44:32 +0200 Subject: [PATCH] =?UTF-8?q?fix(dashboard):=20performance=20dans=20le=20cha?= =?UTF-8?q?rgement=20des=20donn=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/components/Loader.js | 9 ++++++--- dashboard/src/components/DataLoader.js | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/components/Loader.js b/app/src/components/Loader.js index 7a9977c6e..5da3627ed 100644 --- a/app/src/components/Loader.js +++ b/app/src/components/Loader.js @@ -56,9 +56,12 @@ export const refreshTriggerState = atom({ }); export const mergeItems = (oldItems, newItems = []) => { - const newItemsIds = newItems?.map((i) => i._id) || []; - const oldItemsPurged = oldItems.filter((i) => !newItemsIds.includes(i._id)); - return [...oldItemsPurged, ...newItems].filter((e) => !e.deletedAt); + const newItemIds = {}; + for (const newItem of newItems) { + newItemIds[newItem._id] = true; + } + const oldItemsPurged = oldItems.filter((item) => !newItemIds[item._id] && !item.deletedAt); + return [...oldItemsPurged, ...newItems.filter((item) => !item.deletedAt)]; }; export const DataLoader = () => { diff --git a/dashboard/src/components/DataLoader.js b/dashboard/src/components/DataLoader.js index b3a3b2d24..534dafb45 100644 --- a/dashboard/src/components/DataLoader.js +++ b/dashboard/src/components/DataLoader.js @@ -468,9 +468,12 @@ 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)); - return [...oldItemsPurged, ...newItems].filter((e) => !e.deletedAt); + const newItemIds = {}; + for (const newItem of newItems) { + newItemIds[newItem._id] = true; + } + const oldItemsPurged = oldItems.filter((item) => !newItemIds[item._id] && !item.deletedAt); + return [...oldItemsPurged, ...newItems.filter((item) => !item.deletedAt)]; }; const FullScreenContainer = styled.div`