Skip to content

Commit

Permalink
fix(dashboard): performance dans le chargement des données (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudambro authored Sep 27, 2023
1 parent 95de228 commit 8e6d0dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions app/src/components/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
9 changes: 6 additions & 3 deletions dashboard/src/components/DataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 8e6d0dd

Please sign in to comment.