Commit graph

5 commits

Author SHA1 Message Date
Jamie Gaskins
820dd9b5a6
Allow Emails::RemoveOldEmailsWorker to run longer (#15085)
* Allow Emails::RemoveOldEmailsWorker to run longer

We set the SQL statement timeout based on the STATEMENT_TIMEOUT
environment variable (defaulting to 2.5 seconds in production), but not
all SQL queries are created equal. Since some may take longer out of
necessity, this PR introduces a `Model.with_statement_timeout` method
that allows you to change the SQL statement timeout only for a given
block.

* EmailMessage doesn't inherit ApplicationRecord

It inherits from `Ahoy::Message`, which inherits directly from
`ActiveRecord::Base`.

[3] pry(main)> EmailMessage.ancestors
=> [EmailMessage(id: integer, clicked_at: datetime, content: text, feedback_message_id: integer, mailer: string, sent_at: datetime, subject: text, to: text, token: string, user_id: integer, user_type: string, utm_campaign: string, utm_content: string, utm_medium: string, utm_source: string, utm_term: string),
 EmailMessage::GeneratedAssociationMethods,
 EmailMessage::GeneratedAttributeMethods,
 Ahoy::Message(id: integer, clicked_at: datetime, content: text, feedback_message_id: integer, mailer: string, sent_at: datetime, subject: text, to: text, token: string, user_id: integer, user_type: string, utm_campaign: string, utm_content: string, utm_medium: string, utm_source: string, utm_term: string),
 Kaminari::ConfigurationMethods,
 Kaminari::ActiveRecordModelExtension,
 Ahoy::Message::GeneratedAssociationMethods,
 Ahoy::Message::GeneratedAttributeMethods,
 Bullet::SaveWithBulletSupport,
 ActiveRecord::Base,
 ...

* Use milliseconds to match STATEMENT_TIMEOUT units
2021-10-15 11:53:55 -04:00
rhymes
bc385ae6d5
Switch decorators to Rails builtin decorations - take 2 (#6125) [deploy]
* Revert "Revert "[deploy] Switch decorators from Draper to Rails builtin decorations (#6040)" (#6122) [deploy]"

This reverts commit d438349550.

* Enable serialization for decorators

* Refactor and test default home feed serialization

* Improve spec

* Applied @vaidehijoshi suggestions

* Applied @citizen428 suggestions

* Make CodeClimate happy

* Cleanup stories_index_spec.rb

* Refactor UserDecorator#cached_followed_tags to loop less
2020-02-19 15:30:53 -05:00
rhymes
d438349550
Revert "[deploy] Switch decorators from Draper to Rails builtin decorations (#6040)" (#6122) [deploy]
This reverts commit cc53b55a4a.
2020-02-17 11:28:32 -05:00
rhymes
cc53b55a4a
[deploy] Switch decorators from Draper to Rails builtin decorations (#6040)
* Convert SponsorshipDecorator to Rails decorator

* Remove empty ReactionDecorator

* Rename SponsorshipDecorator#level_color_hex to level_background_color

* Convert CommentDecorator to Rails decorator

* Add specs and fix bugs for NotificationDecorator

* Convert NotificationDecorator to Rails decorator

* Add specs and fix bugs for OrganizationDecorator

* Convert OrganizationDecorator to Rails decorator

* Add specs to PodcastEpisodeDecorator and fix bugs

* Convert PodcastEpisodeDecorator to a Rails decorator

* Add missing specs for ArticleDecorator and fix bugs

* Convert ArticleDecorator to Rails decorator

* Add missing specs to UserDecorator and fix issues

* Convert UserDecorator to Rails decorator

* Add .decorate_collection method

* Add decorator for AR relations and remove Draper

* Rename BaseDecorator back to ApplicationDecorator

* Rename .decorate_ back to .decorate

* Restore decorate_collection (WTH)

* Add decorated?

* Fix bugs and failing specs

* Decoration should always be explicit
2020-02-17 09:32:32 -05:00
rhymes
9b2886979a ActiveRecord count optimizations (#5478) [deploy]
* Do not load messages in memory, just to count them
* Add Model.estimated_count
* Use Model.estimated_count in task record_db_table_counts
* Use size and estimated_count
* Use table_name so that .estimated_count works with all models
* Add comment to explain the .load.size + .each pattern
2020-01-14 12:03:38 -05:00