Skip to content

Commit

Permalink
fix(dashboard): performance dans le chargement des données
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Sep 27, 2023
1 parent 4e72227 commit 41fc86c
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 41fc86c

Please sign in to comment.