eBooru/app/models/forum_subscription.rb
Earlopain fc7d84affd
[RuboCop] Enable Style/FrozenStringLiteralComment
This reduces allocations on the posts page by about 5%, from basic testing
2024-02-25 18:15:55 +01:00

27 lines
819 B
Ruby

# frozen_string_literal: true
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) 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