-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Optimize processRecurrence (#9670)
- Loading branch information
1 parent
56a54b3
commit eb6e608
Showing
3 changed files
with
60 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Normalize results with a one to many mapping for the keys, so the key is usually a foreign key | ||
*/ | ||
export const normalizeArrayResults = <KeyT extends string | number, T extends {[key: string]: any}>( | ||
keys: Readonly<KeyT[]>, | ||
results: T[], | ||
key: keyof T | ||
) => { | ||
const map = {} as Record<KeyT, T[]> | ||
results.forEach((result: T) => { | ||
if (!map[result[key]]) { | ||
map[result[key]] = [] as T[] | ||
} | ||
map[result[key]].push(result) | ||
}) | ||
const mappedResults = [] as T[][] | ||
keys.forEach((key) => { | ||
mappedResults.push(map[key]) | ||
}) | ||
return mappedResults | ||
} | ||
|
||
export default normalizeArrayResults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters