Optimise and Refactor `Org.with_template_and_user_counts`
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).
- Updated the query logic for
-
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
deleteoption enabled. These PR changes should result in the same exact Orgs having thedeleteoption enabled as before.
- Updated the code to correspond with the changes made in
-
Refactoring:
-
To reflect these changes,
scope: Org.with_template_and_user_countshas been renamed toscope: Org.with_template_count_and_associations_checkthroughout the codebase. -
In
app/models/org.rb,joins('LEFT OUTER JOIN templates ON orgs.id = templates.org_id')has been replaced with the equivalentleft_outer_joins(:templates) -
The following table compares the
developmentbranch toaaron/optimize-scope-with_template_and_user_countsby 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% |
| 1 Error | |
|---|---|
| :no_entry_sign: | Please include a CHANGELOG entry. |
Generated by :no_entry_sign: Danger