Skip to content

Commit

Permalink
Attempt fixing deadlocks by moving account stats update outside trans…
Browse files Browse the repository at this point in the history
…action (mastodon#9437)

* Use `update_column` instead of `update_attribute` in callback

`update_attribute` would normally cause callbacks to be called.
Called from a callback, it seems to stop further callbacks from executing.

`update_column` does the same work, but without calling callbacks or
preventing other callbacks from executing.

* Fix deadlocks by moving account stats update outside transaction
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent adf7f7f commit 4a1221a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def decrement_count!(key)
update_status_stat!(key => [public_send(key) - 1, 0].max)
end

after_create :increment_counter_caches
after_destroy :decrement_counter_caches
after_create_commit :increment_counter_caches
after_destroy_commit :decrement_counter_caches

after_create_commit :store_uri, if: :local?
after_create_commit :update_statistics, if: :local?
Expand Down Expand Up @@ -429,7 +429,7 @@ def update_status_stat!(attrs)
end

def store_uri
update_attribute(:uri, ActivityPub::TagManager.instance.uri_for(self)) if uri.nil?
update_column(:uri, ActivityPub::TagManager.instance.uri_for(self)) if uri.nil?
end

def prepare_contents
Expand Down

0 comments on commit 4a1221a

Please sign in to comment.