docbrown/app/services
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
..
articles Optimize column selection for articles belonging to "any" given tag (#12420) 2021-01-25 17:34:10 +01:00
audit Rubocop fixes (#11862) 2020-12-11 17:36:42 +03:00
authentication Add Sign in with Apple (#11934) 2020-12-18 10:22:33 -06:00
badges Split BadgeRewarder into multiple services (#11902) 2020-12-23 09:55:06 -05:00
broadcasts/welcome_notification Workaround for Apple auth problems (still in beta) (#12263) 2021-01-14 09:44:56 -06:00
bufferizer Move Bufferizer to services (#12171) 2021-01-08 11:17:20 -05:00
chat_channels 🚀 Ability to allow tag moderators to create chat channels (#9741) 2020-12-08 13:10:36 +07:00
color Move HexComparer to Hex::Comparer service (#12202) 2021-01-12 11:34:30 -05:00
credits Refactoring user_controller separating some classes to service (#10384) 2020-10-05 10:41:59 +02:00
data_sync/elasticsearch Reindex comments' Elasticsearch doc when commentable is updated (#12330) 2021-01-20 09:44:59 -05:00
edge_cache Add sidebar bust logic (#11878) 2020-12-13 19:43:44 -05:00
error_messages Move app/labor/error_message_cleaner.rb to service (#11679) 2020-12-02 11:05:36 +07:00
exporter Update data exporter to handle admin send (#10274) 2020-10-26 18:00:56 -04:00
fastly_config [deploy] Create FastlyConfig & refactor params safe list (#7630) 2020-05-01 11:23:48 -04:00
feeds Remove RssReader (#12169) 2021-01-08 11:45:15 -05:00
follows Move app/labor/follow_checker.rb to service (#11613) 2020-12-01 14:14:36 +07:00
giphy Deduplicate giphy_img? function and add tests (#4590) 2019-10-30 11:40:17 -04:00
github Routine rubocop fixes (#10478) 2020-09-29 10:14:26 -04:00
html Code snippet fullscreen icon - setting constraints for size. (#12010) 2021-01-13 15:17:10 +01:00
images Fix deprecation warnings (#12339) 2021-01-20 10:01:20 +01:00
loggers Move LogWorkerQueueStats from labor to services (#11642) 2020-11-30 09:31:15 +07:00
mailchimp Don't try to unsub users when destroying if Mailchimp is not enabled (#12331) 2021-01-20 12:32:35 -05:00
markdown_processor Move MarkdownTraverser to service (#12282) 2021-01-20 11:29:42 -05:00
mentions Rubocop: enable and fix new Rails cops (#9537) 2020-07-29 11:14:19 +02:00
moderator Move MailchimpBot to Mailchimp::Bot service (#12205) 2021-01-12 10:28:48 -05:00
notifications Remove app/labor/random_gif.rb (#11611) 2020-11-25 14:58:32 +00:00
payments Refactor: Send RSS Reader and Payment Errors to Honeybadger (#9209) 2020-07-09 08:48:52 +02:00
podcasts [deploy] Ensure podcast episodes are created with processed_html (#10715) 2020-10-07 12:09:36 -04:00
profile_fields Remove contact_consent from users (#12196) 2021-01-12 16:18:47 -05:00
profiles Remove autofollowing hiring tag (#11722) 2020-12-23 12:11:19 +07:00
re_captcha Split ReCaptcha service and use verbs instead of pronouns (#11706) 2020-12-02 16:50:42 -06:00
search Feature:Backend Username Search Endpoint for Mention Completion (#11479) 2020-11-18 16:43:59 -06:00
secrets Use a sortable unique ID for the event_id (#3972) 2019-09-09 10:15:12 -04:00
site_configs Fix domain list bug (#12268) 2021-01-14 10:43:42 -05:00
slack Fix deprecation warnings (#12339) 2021-01-20 10:01:20 +01:00
suggester/users Refactor:Replace Production Check with Average Metrics (#11096) 2020-11-12 10:03:10 -06:00
tag_moderators Move MailchimpBot to Mailchimp::Bot service (#12205) 2021-01-12 10:28:48 -05:00
twilio Move Twilio from labor to services (#11824) 2020-12-10 10:21:09 +07:00
twitter_client Use SiteConfig twitter keys before env (#12200) 2021-01-11 12:01:37 -05:00
user_blocks Remove algolia from chat channel memberships (#6323) 2020-02-27 09:59:12 -05:00
user_subscriptions Update CODEOWNERS and team names in TODO comments (#9460) 2020-07-24 12:17:20 +07:00
users Update bust to EdgeCache::Bust (#12052) 2020-12-29 09:53:15 +01:00
webhook Move Webhook::DispatchEventJob to Sidekiq (#5722) [deploy] 2020-01-27 14:36:27 -05:00
analytics_service.rb Rubocop: enable and fix new Rails cops (#9537) 2020-07-29 11:14:19 +02:00
application_service.rb [deploy] Refactor 🚀 : Replaced Chat Channel Setting page with Preact component. (#8271) 2020-06-10 16:58:37 -04:00
article_api_index_service.rb Optimize column selection for articles belonging to "any" given tag (#12420) 2021-01-25 17:34:10 +01:00
article_with_video_creation_service.rb Upgrade Rubocop to 0.81 (#7219) 2020-04-11 10:10:04 +02:00
bulk_sql_delete.rb Use SQL DELETE statement to delete notifications without a SELECT (#5303) [deploy] 2019-12-31 07:30:27 -06:00
email_digest.rb Refactor:Use dev_to? to Check for DEV (#12083) 2020-12-30 14:34:00 -06:00
email_digest_article_collector.rb Optimization:Select Only Necessary Columns from Ahoy Messages For Digest Emails (#10194) 2020-09-03 16:46:33 -04:00
feature_flag.rb Remove RssReader (#12169) 2021-01-08 11:45:15 -05:00
flare_tag.rb [deploy] Refactor Flare Tag Class (#9064) 2020-07-01 16:57:03 -04:00
medium_article_retrieval_service.rb Nokogiri::HTML should receive the body, not the response object (#5297) 2019-12-31 08:46:49 -05:00
notifications.rb Remove notifiable access from articles and comments notifications (#5415) [deploy] 2020-01-09 10:19:45 -05:00
rate_limit_checker.rb [deploy] Limit articles created by newer users (#10686) 2020-10-06 21:02:05 -04:00
tag_adjustment_creation_service.rb [deploy] Rubocop: fix violations of Layout/LineLength (#9197) 2020-07-08 08:36:36 -05:00
tag_adjustment_update_service.rb [WIP] Allow mods to remove tags and send user notification (#1252) 2018-12-04 16:45:32 -05:00