Skip to content

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.rb
index 28bb418a30f..be2a5de02c1 100644
--- a/app/jobs/regular/user_email.rb
+++ b/app/jobs/regular/user_email.rb
@@ -45,6 +45,12 @@ module Jobs
if message
Email::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)
+ end
else
skip_reason_type
end
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 6f4a14d3181..f3fb4494ab3 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -841,6 +841,9 @@ email:
default: 4
min: 1
bounce_score_threshold_deactivate: 30
+ bounce_score_erode_on_send:
+ default: 0.1
+ hidden: true
soft_bounce_score:
default: 1
min: 1
diff --git a/db/migrate/20180828065005_change_bounce_score_to_float.rb b/db/migrate/20180828065005_change_bounce_score_to_float.rb
new file mode 100644
index 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
+end
diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb
index 25dd02807c5..202d2df331d 100644
--- a/spec/jobs/user_email_spec.rb
+++ b/spec/jobs/user_email_spec.rb
@@ -291,6 +291,34 @@ describe Jobs::UserEmail do
end
end
+ 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" do
user.user_stat.update(bounce_score: SiteSetting.bounce_score_threshold)