Skip to content

Commit

Permalink
fix(dashboard): perf on merged items
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Sep 27, 2023
1 parent 4e72227 commit 98c1d3a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dashboard/src/components/DataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit 98c1d3a

Please sign in to comment.