-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PERF: Speed up
PostSerializer#reactions
by avoiding nested loop tak…
…e 2 (#313) This is a follow-up to 7467349. Within the `object.post_actions.reject` loop, we are running through another loop given by `object.post_actions_with_reaction_users&.find`. When the `object.post_actions` and `object.post_actions_with_reaction_users` array is large, we end up spending alot of time executing the loops. This commit resolves the problem by reducing the number of records we loop in `object.post_actions_with_reaction_users` by prefiltering the records by `post_action.id` to remove alot of unnecessary iterations in the loop. Local benchmarks for the method for 8000 items in `object.post_actions` records and 2000 items in `post_actions_with_reaction_users` shows the runtime of the method decreasing from roughly 7seconds to about 5ms.
- Loading branch information
Showing
3 changed files
with
15 additions
and
13 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
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