roadmap icon indicating copy to clipboard operation
roadmap copied to clipboard

Optimise and Refactor `Org.with_template_and_user_counts`

Open aaronskiba opened this issue 1 year ago • 1 comments

Changes proposed in this PR:

  • app/models/org.rb

    • Updated the query logic for scope :with_template_and_user_counts. It is now significantly faster (see table at bottom of description).
  • app/views/paginable/orgs/_index.html.erb

    • Updated the code to correspond with the changes made in app/models/org.rb.
    • The code updated in this file is for determining whether or not a listed Org should have the delete option enabled. These PR changes should result in the same exact Orgs having the delete option enabled as before.
  • Refactoring:

  • To reflect these changes, scope: Org.with_template_and_user_counts has been renamed to scope: Org.with_template_count_and_associations_check throughout the codebase.

  • In app/models/org.rb, joins('LEFT OUTER JOIN templates ON orgs.id = templates.org_id') has been replaced with the equivalent left_outer_joins(:templates)

  • The following table compares the development branch to aaron/optimize-scope-with_template_and_user_counts by making requests to the various paths affected by this PR. The benchmarking was performed via ab - Apache HTTP server benchmarking tool alongside a recent (May 2024) db dump from the production environment of DMP Assistant. In both cases, 100 consecutive requests were performed to each path and the recorded result is the mean request time (ms).

Path mean request time (ms) before mean request time (ms) now % change
/super_admin/orgs 1090.878 61.887 -94.33%
/paginable/orgs/index/ALL 3322.034 328.263 -90.12%

aaronskiba avatar Jun 25 '24 22:06 aaronskiba

</tr>
1 Error
:no_entry_sign:

Please include a CHANGELOG entry.

You can find it at [CHANGELOG.md](https://github.com/DMPRoadmap/roadmap/blob/main/CHANGELOG.md).

Generated by :no_entry_sign: Danger

github-actions[bot] avatar Jun 25 '24 22:06 github-actions[bot]