A platform for community discussion. Free, open, simple.
FEATURE: erode bounce score every time an email is sent
Sam740308675bc6
diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rbindex 28bb418a30f..be2a5de02c1 100644--- a/app/jobs/regular/user_email.rb+++ b/app/jobs/regular/user_email.rb@@ -45,6 +45,12 @@ module Jobsif messageEmail::Sender.new(message, type, user).send+ if (b = user.user_stat.bounce_score) > SiteSetting.bounce_score_erode_on_send+ # erode bounce score each time we send an email+ # this means that we are punished a lot less for bounces+ # and we can recover more quickly+ user.user_stat.update(bounce_score: b - SiteSetting.bounce_score_erode_on_send)+ endelseskip_reason_typeenddiff --git a/config/site_settings.yml b/config/site_settings.ymlindex 6f4a14d3181..f3fb4494ab3 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -841,6 +841,9 @@ email:default: 4min: 1bounce_score_threshold_deactivate: 30+ bounce_score_erode_on_send:+ default: 0.1+ hidden: truesoft_bounce_score:default: 1min: 1diff --git a/db/migrate/20180828065005_change_bounce_score_to_float.rb b/db/migrate/20180828065005_change_bounce_score_to_float.rbnew file mode 100644index 00000000000..b2cd5a4a71f--- /dev/null+++ b/db/migrate/20180828065005_change_bounce_score_to_float.rb@@ -0,0 +1,5 @@+class ChangeBounceScoreToFloat < ActiveRecord::Migration[5.2]+ def change+ change_column :user_stats, :bounce_score, :float+ end+enddiff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rbindex 25dd02807c5..202d2df331d 100644--- a/spec/jobs/user_email_spec.rb+++ b/spec/jobs/user_email_spec.rb@@ -291,6 +291,34 @@ describe Jobs::UserEmail doendend+ it "erodes bounce score each time an email is sent" do+ SiteSetting.bounce_score_erode_on_send = 0.2++ user.user_stat.update(bounce_score: 2.7)++ Jobs::UserEmail.new.execute(+ type: :user_mentioned,+ user_id: user.id,+ notification_id: notification.id,+ post_id: post.id+ )++ user.user_stat.reload+ expect(user.user_stat.bounce_score).to eq(2.5)++ user.user_stat.update(bounce_score: 0)++ Jobs::UserEmail.new.execute(+ type: :user_mentioned,+ user_id: user.id,+ notification_id: notification.id,+ post_id: post.id+ )++ user.user_stat.reload+ expect(user.user_stat.bounce_score).to eq(0)+ end+it "does not send notification if bounce threshold is reached" douser.user_stat.update(bounce_score: SiteSetting.bounce_score_threshold)