docbrown/app/controllers/admin
rhymes def0cf2437
Optimize column selection for articles belonging to "any" given tag (#12420)
When `acts-as-taggable-on`'s `.tagged_with()` is used with `any: true`,
the gem will use `SELECT *` regardless of any previous (or following) requests
of selecting a limited amount of columns.

Given that the `articles` table has [73 columns](https://dev.to/admin/blazer/queries/314-number-of-columns-in-all-tables)
that will amount to wasted RAM memory for columns we don't need.

By "unscoping" any previous `select()` we can optimize used memory.

Before:

```ruby
[24] pry(main)> Article.tagged_with([:ruby], any: true).select(:id, :name).to_sql
=> "SELECT \"articles\".*, \"articles\".\"id\", \"name\" FROM \"articles\" WHERE EXISTS (SELECT * FROM \"taggings\" WHERE \"taggings\".\"taggable_id\" = \"articles\".\"id\" AND \"taggings\".\"taggable_type\" = 'Article' AND \"taggings\".\"tag_id\" IN (SELECT \"tags\".\"id\" FROM \"tags\" WHERE (\"tags\".\"name\" LIKE 'ruby' ESCAPE '!')))"
```

Note, how the SQL query is `articles.*, articles.column_a`

After:

[25] pry(main)> Article.tagged_with([:ruby], any: true).unscope(:select).select(:id, :name).to_sql
=> "SELECT \"articles\".\"id\", \"name\" FROM \"articles\" WHERE EXISTS (SELECT * FROM \"taggings\" WHERE \"taggings\".\"taggable_id\" = \"articles\".\"id\" AND \"taggings\".\"taggable_type\" = 'Article' AND \"taggings\".\"tag_id\" IN (SELECT \"tags\".\"id\" FROM \"tags\" WHERE (\"tags\".\"name\" LIKE 'ruby' ESCAPE '!')))"
```

`articles.*` is gone :-)

- https://github.com/mbleigh/acts-as-taggable-on/issues/936
- 47da5036de/lib/acts_as_taggable_on/taggable/tagged_with_query/any_tags_query.rb (L2-L8)
2021-01-25 17:34:10 +01:00
..
tags Move AssignTagModerator from labor to services (#11826) 2020-12-17 09:51:26 +07:00
users Confirmations that users GDPR data was deleted (#11039) 2020-12-14 12:49:45 +03:00
admin_portals_controller.rb Add admin index (#10957) 2020-10-20 11:11:28 -04:00
application_controller.rb Add config post route for admin api (#11698) 2020-12-22 15:50:34 -05:00
articles_controller.rb Optimize column selection for articles belonging to "any" given tag (#12420) 2021-01-25 17:34:10 +01:00
badge_achievements_controller.rb Add the Ability to Remove Badge Achievements From Users (#9896) [deploy] 2020-08-25 11:14:47 -06:00
badges_controller.rb Add the Ability to Remove Badge Achievements From Users (#9896) [deploy] 2020-08-25 11:14:47 -06:00
broadcasts_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
buffer_updates_controller.rb Move Bufferizer to services (#12171) 2021-01-08 11:17:20 -05:00
chat_channels_controller.rb [deploy] [Admin Tooling] Allow admins delete empty Connect Channels (#9873) 2020-08-20 14:55:48 +02:00
comments_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
configs_controller.rb Add config post route for admin api (#11698) 2020-12-22 15:50:34 -05:00
data_update_scripts_controller.rb Basic MVP version of data update script page (#12167) 2021-01-07 23:12:51 +02:00
display_ads_controller.rb Bust sidebar when display ad is updated (#12025) 2020-12-25 11:02:19 -06:00
email_messages_controller.rb Remove resource_admin dashboards (Administrate) (#11792) 2020-12-08 12:38:13 -06:00
events_controller.rb Refactor Admin Events Index (#11103) [deploy] 2020-10-29 10:11:15 -06:00
feedback_messages_controller.rb [deploy] Enable admin-configured app_domain (#10206) 2020-09-11 09:38:34 -04:00
html_variants_controller.rb [deploy] HTML Variant admin dashboard (#10188) 2020-09-28 09:22:13 -06:00
invitations_controller.rb Confirmations that users GDPR data was deleted (#11039) 2020-12-14 12:49:45 +03:00
listing_categories_controller.rb [deploy] Manage listing categories in dashboard (#10506) 2020-10-02 11:05:09 -04:00
listings_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
moderator_actions_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
mods_controller.rb Move AssignTagModerator from labor to services (#11826) 2020-12-17 09:51:26 +07:00
navigation_links_controller.rb [deploy] Bust caches when navigation links are changed (#10865) 2020-10-21 21:30:31 -04:00
organization_memberships_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
organizations_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
pages_controller.rb Replace collective_noun with community_name (#11846) [deploy] 2020-12-28 09:34:17 -07:00
permissions_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
podcasts_controller.rb Allow admin to add users as podcast owners (MLH Fellowship) (#11728) [deploy] 2020-12-17 10:55:16 -07:00
privileged_reactions_controller.rb Upgrade rubocop* packages to the latest version and fix violations (#11972) 2020-12-21 18:29:43 +01:00
profile_field_groups_controller.rb Profile Admin updates (#10133) 2020-09-02 12:32:25 +02:00
profile_fields_controller.rb [deploy] Add display_area & show_in_onboarding to the profile setup ui (#10158) 2020-09-02 16:30:33 -05:00
reactions_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
response_templates_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
secrets_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
sponsorships_controller.rb Adds ability to create new sponsorships from admin dashboard (#10187) 2020-09-03 10:10:37 -06:00
tags_controller.rb Add sorting feature to /admin/tags (#12249) 2021-01-13 17:03:17 -05:00
tools_controller.rb Update bust to EdgeCache::Bust (#12052) 2020-12-29 09:53:15 +01:00
users_controller.rb Remove GitHub repositories when GitHub identity is removed (#11951) 2020-12-20 15:15:40 +01:00
webhook_endpoints_controller.rb [deploy] Move /internal to `/admin (#9639) 2020-08-07 10:36:26 -04:00
welcome_controller.rb [deploy] Add community_name to site config (#9864) 2020-08-19 14:54:40 -04:00