From 526b66e871ecae0bf7fcfdf374a250f9b1d6bfdf Mon Sep 17 00:00:00 2001 From: Lex Alexander Date: Thu, 12 Oct 2017 14:52:09 -1000 Subject: [PATCH] Retoot count increases without reason (#5363) * Retoot count increases without reason -The store_uri method for Statuses was being called on after_create and causing reblogs to be incremented twice. -This calls it when the transaction is finished by using after_create_commit. -Fixes #4916. * Added test case for after_create_commit callback for checking reblog count. * Rewrote test to keep original, but added one for only the after_create_commit callback. --- app/models/status.rb | 2 +- spec/services/reblog_service_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/status.rb b/app/models/status.rb index 0d249244f3..6db1f2a4c8 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -134,7 +134,7 @@ class Status < ApplicationRecord CustomEmoji.from_text([spoiler_text, text].join(' '), account.domain) end - after_create :store_uri, if: :local? + after_create_commit :store_uri, if: :local? around_create Mastodon::Snowflake::Callbacks diff --git a/spec/services/reblog_service_spec.rb b/spec/services/reblog_service_spec.rb index 0ad5c5f6ba..19d3bb6cb7 100644 --- a/spec/services/reblog_service_spec.rb +++ b/spec/services/reblog_service_spec.rb @@ -39,6 +39,12 @@ RSpec.describe ReblogService do expect(status.reblogs.count).to eq 1 end + describe 'after_create_commit :store_uri' do + it 'keeps consistent reblog count' do + expect(status.reblogs.count).to eq 1 + end + end + it 'distributes to followers' do expect(ActivityPub::DistributionWorker).to have_received(:perform_async) end