Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PERF: Speed up PostSerializer#reactions by avoiding nested loop take 2 #313

Merged
merged 1 commit into from
Oct 11, 2024

Commits on Oct 11, 2024

  1. PERF: Speed up PostSerializer#reactions by avoiding nested loop take 2

    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.
    tgxworld committed Oct 11, 2024
    Configuration menu
    Copy the full SHA
    b641675 View commit details
    Browse the repository at this point in the history