Drop forum subscriptions.

Few people used forum subscriptions (only around 100), and even fewer
people were subscribed to active threads. Most subscriptions were for
old threads that will never be bumped again. The implementation also had
a few problems:

* Unsubscribe links in emails didn't work (they unset the user's
  receive_email_notifications flag, but forum subscriptions didn't
  respect this flag).
* Some users had invalid email addresses, which caused notifications to
  bounce. There was no mechanism for preventing bounces.
* The implementation wasn't scalable. It involved a daily linear scan
  over _all_ forum subscriptions looking for any topics that had been updated.
This commit is contained in:
evazion
2020-01-19 13:44:09 -06:00
parent cae9a5d7e3
commit 13528ac2d3
12 changed files with 11 additions and 149 deletions

View File

@@ -1,24 +0,0 @@
class ForumSubscription < ApplicationRecord
belongs_to :user
belongs_to :forum_topic
def self.prune!
where("last_read_at < ?", 3.months.ago).delete_all
end
def self.process_all!
ForumSubscription.find_each do |subscription|
forum_topic = subscription.forum_topic
if forum_topic.updated_at > subscription.last_read_at
CurrentUser.scoped(subscription.user, "127.0.0.1") do
forum_posts = forum_topic.posts.where("created_at > ?", subscription.last_read_at).order("id desc")
begin
UserMailer.forum_notice(subscription.user, forum_topic, forum_posts).deliver_now
rescue Net::SMTPSyntaxError
end
subscription.update_attribute(:last_read_at, forum_topic.updated_at)
end
end
end
end
end

View File

@@ -16,7 +16,6 @@ class ForumTopic < ApplicationRecord
has_many :posts, -> {order("forum_posts.id asc")}, :class_name => "ForumPost", :foreign_key => "topic_id", :dependent => :destroy
has_many :moderation_reports, through: :posts
has_one :original_post, -> {order("forum_posts.id asc")}, class_name: "ForumPost", foreign_key: "topic_id", inverse_of: :topic
has_many :subscriptions, :class_name => "ForumSubscription"
before_validation :initialize_is_deleted, :on => :create
validates_presence_of :title
validates_associated :original_post
@@ -126,16 +125,9 @@ class ForumTopic < ApplicationRecord
end
end
module SubscriptionMethods
def user_subscription(user)
subscriptions.where(:user_id => user.id).first
end
end
extend SearchMethods
include CategoryMethods
include VisitMethods
include SubscriptionMethods
def editable_by?(user)
(creator_id == user.id || user.is_moderator?) && visible?(user)