docbrown/app
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
..
assets Fixing link focus (#12362) 2021-01-22 09:26:51 -05:00
black_box Small adjustment to blackbox.rb (#10961) 2020-10-20 21:14:56 -04:00
controllers Optimize column selection for articles belonging to "any" given tag (#12420) 2021-01-25 17:34:10 +01:00
decorators Improve cumulative layout shift on comment reactions + optimizations (#12309) 2021-01-18 19:29:44 -05:00
errors [deploy] Add contexts and permissions to liquid tags (#8917) 2020-06-30 14:53:18 -04:00
helpers Prevent text overflow of follow button (#12422) 2021-01-25 17:29:10 +01:00
javascript Fixing link focus (#12362) 2021-01-22 09:26:51 -05:00
lib generalise sidebar campaign published article timeframe (#12278) 2021-01-19 08:40:39 -06:00
liquid_tags Bump liquid from 4.0.3 to 5.0.0 (#12150) 2021-01-15 15:37:42 -06:00
mailers Replace collective_noun with community_name (#11846) [deploy] 2020-12-28 09:34:17 -07:00
middlewares Move TimeZoneSetter middleware in proper place (#11336) 2020-11-09 17:11:10 +01:00
models Optimize column selection for articles belonging to "any" given tag (#12420) 2021-01-25 17:34:10 +01:00
policies Verify current password on password change (#12174) 2021-01-21 12:40:54 +07:00
queries/admin Filter by a few other roles when adding potential mods (#11187) 2020-11-02 15:05:19 -05:00
refinements Drop profile columns from user (#10707) 2020-12-03 08:14:38 +07:00
sanitizers [deploy] Rubocop: fix violations of Layout/LineLength (#9197) 2020-07-08 08:36:36 -05:00
serializers Reindex comments' Elasticsearch doc when commentable is updated (#12330) 2021-01-20 09:44:59 -05:00
services Optimize column selection for articles belonging to "any" given tag (#12420) 2021-01-25 17:34:10 +01:00
uploaders [deploy] Bug Fix: Validate GIFs Frames and Add MiniMagick Timeout (#9319) 2020-07-15 09:49:24 -05:00
validators Fix misleading comment (#11847) 2020-12-10 12:34:23 -06:00
view_objects Move GeneratedImage to Images::GenerateSocialmage (#11691) 2020-12-02 11:03:14 +07:00
views Fix flash of unstyled content (#12385) 2021-01-25 10:49:58 -05:00
workers Save Data Update Script errors to database and show them on http://localhost:3000/admin/data_update_scripts (#12348) 2021-01-21 14:48:34 +01:00