about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-08-18 14:55:03 +0200
committerGitHub <noreply@github.com>2019-08-18 14:55:03 +0200
commit96702e7f6727d9c688b2c6e2527c4a5bfefff886 (patch)
tree3e682e173d7bca9b3f610e01c31352214358a355 /app/models
parent8a555534ec0fbee3e1b842ca84f9a1c6e1160c5d (diff)
Add `tootctl cache recount` command (#11597)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/account_counters.rb3
-rw-r--r--app/models/status.rb7
2 files changed, 7 insertions, 3 deletions
diff --git a/app/models/concerns/account_counters.rb b/app/models/concerns/account_counters.rb
index 3581df8dd..6e25e1905 100644
--- a/app/models/concerns/account_counters.rb
+++ b/app/models/concerns/account_counters.rb
@@ -26,7 +26,8 @@ module AccountCounters
   private
 
   def save_account_stat
-    return unless account_stat&.changed?
+    return unless association(:account_stat).loaded? && account_stat&.changed?
+
     account_stat.save
   end
 end
diff --git a/app/models/status.rb b/app/models/status.rb
index 23682c84b..0538c4e9e 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -388,13 +388,16 @@ class Status < ApplicationRecord
     end
   end
 
+  def status_stat
+    super || build_status_stat
+  end
+
   private
 
   def update_status_stat!(attrs)
     return if marked_for_destruction? || destroyed?
 
-    record = status_stat || build_status_stat
-    record.update(attrs)
+    status_stat.update(attrs)
   end
 
   def store_uri