Remove comments user_touch job and do it inline when comment is created (#5378) [deploy]
This commit is contained in:
parent
bc8c177966
commit
a572a96921
4 changed files with 17 additions and 47 deletions
|
|
@ -1,10 +0,0 @@
|
|||
module Comments
|
||||
class TouchUserJob < ApplicationJob
|
||||
queue_as :comments_touch_user
|
||||
|
||||
def perform(comment_id)
|
||||
comment = Comment.find_by(id: comment_id)
|
||||
comment&.user&.touch(:updated_at, :last_comment_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -251,7 +251,7 @@ class Comment < ApplicationRecord
|
|||
end
|
||||
|
||||
def touch_user
|
||||
Comments::TouchUserJob.perform_later(id)
|
||||
user&.touch(:updated_at, :last_comment_at)
|
||||
end
|
||||
|
||||
def expire_root_fragment
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Comments::TouchUserJob, type: :job do
|
||||
include_examples "#enqueues_job", "comments_touch_user", 1
|
||||
|
||||
describe "#perform_now" do
|
||||
context "with comment" do
|
||||
let_it_be(:article) { create(:article) }
|
||||
let_it_be(:comment) { create(:comment, commentable: article) }
|
||||
let_it_be(:user) { comment.user }
|
||||
let_it_be(:touched_at) { 5.minutes.from_now.beginning_of_minute }
|
||||
|
||||
it "touches user updated_at and last_comment_at columns", :aggregate_failures do
|
||||
Timecop.freeze(touched_at) do
|
||||
described_class.perform_now(comment.id)
|
||||
|
||||
user.reload
|
||||
expect(user.updated_at).to eq(touched_at)
|
||||
expect(user.last_comment_at).to eq(touched_at)
|
||||
end
|
||||
end
|
||||
|
||||
it "does not break if the comment has no user" do
|
||||
comment.update(user: nil)
|
||||
|
||||
expect { described_class.perform_now(comment.id) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context "without comment" do
|
||||
it "does not break" do
|
||||
expect { described_class.perform_now(nil) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -255,6 +255,22 @@ RSpec.describe Comment, type: :model do
|
|||
comment.save
|
||||
end.to change(Comments::CreateFirstReactionWorker.jobs, :size).by(1)
|
||||
end
|
||||
|
||||
it "touches user updated_at" do
|
||||
user.updated_at = 1.month.ago
|
||||
user.save
|
||||
comment = build(:comment, user: user, commentable: article)
|
||||
|
||||
expect { comment.save }.to change(user, :updated_at)
|
||||
end
|
||||
|
||||
it "touches user last_comment_at" do
|
||||
user.last_comment_at = 1.month.ago
|
||||
user.save
|
||||
comment = build(:comment, user: user, commentable: article)
|
||||
|
||||
expect { comment.save }.to change(user, :last_comment_at)
|
||||
end
|
||||
end
|
||||
|
||||
context "when callbacks are triggered before save" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue