about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2018-12-05 22:51:12 +0100
committerEugen Rochko <eugen@zeonfederated.com>2018-12-05 22:51:12 +0100
commit1a22eff1e00194e50751f2ea91ec7326ef15b4fc (patch)
tree0949bc99fbb64ab687f1e1e008ea81338757d0e2
parent9897cf0701d1fb588f9b0defcbd78d0a2095230a (diff)
Attempt fixing deadlocks by moving account stats update outside transaction (#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
-rw-r--r--app/models/status.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index 2e894a6f1..0705ba4c1 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -236,8 +236,8 @@ class Status < ApplicationRecord
     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?
@@ -426,7 +426,7 @@ class Status < ApplicationRecord
   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