docbrown/app/services
Daniel Uber cd835c281f
Periodic Digest Email frequency should be in days (#15904)
* Use the most recent timestamp from sent digest messages

The original logic here had queried for up to 10 (unordered) messages
from the database for this user, perhaps leveraging the knowledge that
we purge old messages after 90 days to ensure 10 was enough.

Since the last message in the limited and unordered list could have
had any sent_at time in the past 90 days, it's possible users could
pass the "should send email" check multiple times in a day (and get
multiple digest emails, I'm not certain when the rake task runs but it
could be as frequently as once per deployment?)

Since we're only using this list of messages to find the most recently
sent message, select the maximum sent time.

* convert periodic_email_digest setting to days

Time.current - last_email_sent_at gives an integer count of elapsed
seconds

Settings::General.periodic_email_digest is an integer count of days
between digests.

Convert to days (so we're only sending digests when enough time has
elapsed) instead of defaulting to once every 2 seconds (or at least
several times per day).

* Clean up comparison

Rather than subtracting the current time from the last time, and
checking that the difference in time is greater than the periodic
setting, use days.ago to get the timestamp far enough in the past, and
ensure last email was sent before that ( `sent_at < n.days.ago` ).

This seems like it reads clearer than the original implementation.

* Prefer Time.before? to numeric comparison

Change the method name from last_email_sent_at to last_email_sent, so
that the comparison reads like English (the other callers use it as a
number)

And since the code reveals its intention clearly, there's no need for
an inline comment about the next line any more.
2021-12-30 09:23:24 -06:00
..
articles Refactoring to leverage an Article scope (#15850) 2021-12-29 09:25:31 -05:00
audit Rubocop fixes (#11862) 2020-12-11 17:36:42 +03:00
authentication Error message after authentication failure due to email address not being whitelisted (#15779) 2021-12-15 21:25:27 +01:00
badges Skip badge awards for spam accounts (#15344) 2021-11-10 10:48:01 -06:00
broadcasts/welcome_notification Bump rubocop-performance from 1.10.2 to 1.11.0 (#13471) 2021-04-22 09:31:25 -05:00
color Rubocop fixes (#15892) 2021-12-28 09:11:41 -06:00
credits Fix app/services' ruby 2.7 kwargs warnings (#13177) 2021-04-01 18:40:50 -04:00
discover Add Forem Discover registration worker and service (#14865) 2021-10-01 10:27:31 -04:00
edge_cache ✂✂✂ Remove events (#15062) 2021-10-15 09:31:08 -04:00
error_messages Remove redundant freeze calls (#14596) 2021-08-26 10:01:08 -04:00
exporter Fix app/services' ruby 2.7 kwargs warnings (#13177) 2021-04-01 18:40:50 -04:00
fastly_config Abstract DatadogStatsClient to ForemStatsClient (#12304) 2021-01-27 11:25:44 -05:00
feeds Use the rss item's url when handling relative image links (#15497) 2021-12-09 14:08:54 -06:00
follows Fix UI showing "Following" after unfollowing a user (#13757) 2021-05-19 17:40:38 +01:00
giphy Deduplicate giphy_img? function and add tests (#4590) 2019-10-30 11:40:17 -04:00
github Spelling (#15702) 2021-12-07 06:59:10 -07:00
homepage [Search 2.0] Add query filters for profile, organization and tag index pages (#13510) 2021-04-27 08:49:47 +02:00
html Remove line break after linking username mentions (#15788) 2021-12-16 10:39:07 -06:00
images Fix rotation of images uploaded from iPhones (#15010) 2021-10-11 15:17:14 -04:00
loggers Rubocop fixes (#15892) 2021-12-28 09:11:41 -06:00
mailchimp Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
markdown_processor Disable dash replacement filter in markdown fixer (#15839) 2021-12-20 15:39:55 -06:00
mentions Issue #9077 has already been resolved, added specs (#15342) 2021-11-17 11:27:50 +02:00
moderator Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
notification_subscriptions Add Article post_commit when user_id changes with specs (#15132) 2021-10-25 10:53:21 +07:00
notifications User correct username in mobile mention notifications (#15861) 2021-12-22 10:31:22 -06:00
organizations Organizations delete optimizations and refactoring (#13610) 2021-05-11 12:14:55 +03:00
payments Validate payment info present before attempting to process (#15629) 2021-12-03 13:09:23 -06:00
podcasts views/podcasts, views/podcast_episodes i18n (#15020) 2021-10-25 14:32:51 +01:00
profile_fields Refactor profile refreshing (#14643) 2021-09-13 12:15:04 -04:00
push_notifications Have specs run without Redis and refactor ConsumerApp and Device (#13647) 2021-05-07 08:03:16 +02:00
re_captcha Spelling fixes to live code (#15670) 2021-12-06 12:11:25 +02:00
search Ensuring reading list excludes unpublished articles (#15490) 2021-11-24 13:22:26 -05:00
settings Added the logo upload to the admin -> customization -> config -> images section. (#15729) 2021-12-15 14:10:27 -05:00
slack Replacing User#warned with User#warned? (#15628) 2021-12-01 13:14:16 -05:00
spam Refactoring Spam Handler (#15412) 2021-11-30 12:45:12 -05:00
tag_moderators Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
twitter_client Split Settings::Authentication from SiteConfig (#13095) 2021-04-12 09:41:09 +02:00
user_subscriptions Fix typo in create_from_controller_params.rb (#15171) 2021-10-25 10:42:40 -07:00
users Remove webhooks and related code (#15827) 2021-12-28 10:56:37 +07:00
analytics_service.rb Add counts for number of views when showing referrers (#14600) 2021-08-27 08:03:43 -05: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 Factoring code to define Article.approved (#15600) 2021-12-01 22:45:32 -05:00
article_with_video_creation_service.rb Use new UserSetting and UserNotificationSettings and Ignore Related User Table Fields (#14121) 2021-07-08 09:31:34 -05:00
bulk_sql_delete.rb Remove txn from with_statement_timeout block (#15088) 2021-10-15 14:53:35 -04:00
email_digest.rb Use new UserSetting and UserNotificationSettings and Ignore Related User Table Fields (#14121) 2021-07-08 09:31:34 -05:00
email_digest_article_collector.rb Periodic Digest Email frequency should be in days (#15904) 2021-12-30 09:23:24 -06:00
feature_flag.rb Updating documentation on FeatureFlag.accessible? (#15492) 2021-11-29 20:25:17 -05:00
flare_tag.rb [Search 2.0] Homepage query (#13339) 2021-04-21 12:41:24 +02:00
instrumentation.rb Instrument EmailDigestArticleCollector (#13153) 2021-03-29 09:33:32 -04:00
markdown_processor.rb Extracting container for allowed tags & attrs (#15338) 2021-12-16 12:24:45 -05:00
medium_article_retrieval_service.rb Fix app/services' ruby 2.7 kwargs warnings (#13177) 2021-04-01 18:40:50 -04: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 Pin posts to feed (#13807) 2021-06-04 10:54:53 +02: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