Skip to content

Commit

Permalink
fix joinByKey perf
Browse files Browse the repository at this point in the history
  • Loading branch information
clyfish committed Mar 7, 2024
1 parent 2a1a32d commit bb87d97
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function joinByKey(
const keys = castArray(key);
// Create a map to quickly query the key of group.
const map = new Map();
return items.reduce<Array<Record<string, any>>>((prev, current) => {
items.forEach((current) => {
// The key of the map is a stable JSON string of the values from given keys.
// We need stable JSON string to support plain object values.
const stableKey = stableStringify(keys.map((k) => current[k]));
Expand All @@ -72,7 +72,6 @@ export function joinByKey(
} else {
map.set(stableKey, { ...current });
}

return [...map.values()];
}, []);
});
return [...map.values()];
}

0 comments on commit bb87d97

Please sign in to comment.