diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2020-12-22 17:13:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-22 17:13:55 +0100 |
commit | 9915d11c0d7a15b6775af8e78fcc4d836368f88d (patch) | |
tree | b6b5efe86ab2686eda673e81b10e05d17af30cf9 /app/models | |
parent | 67ebd61f1180e63fcc671c583e7251e1e09755d9 (diff) |
Fix unnecessary queries when batch-removing statuses, 100x faster (#15387)
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/favourite.rb | 2 | ||||
-rw-r--r-- | app/models/status.rb | 12 |
2 files changed, 3 insertions, 11 deletions
diff --git a/app/models/favourite.rb b/app/models/favourite.rb index bf0ec4449..35028b7dd 100644 --- a/app/models/favourite.rb +++ b/app/models/favourite.rb @@ -36,7 +36,7 @@ class Favourite < ApplicationRecord end def decrement_cache_counters - return if association(:status).loaded? && (status.marked_for_destruction? || status.marked_for_mass_destruction?) + return if association(:status).loaded? && status.marked_for_destruction? status&.decrement_count!(:favourites_count) end end diff --git a/app/models/status.rb b/app/models/status.rb index 96d90e1c2..b426f9d5b 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -228,14 +228,6 @@ class Status < ApplicationRecord @emojis = CustomEmoji.from_text(fields.join(' '), account.domain) end - def mark_for_mass_destruction! - @marked_for_mass_destruction = true - end - - def marked_for_mass_destruction? - @marked_for_mass_destruction - end - def replies_count status_stat&.replies_count || 0 end @@ -430,7 +422,7 @@ class Status < ApplicationRecord end def decrement_counter_caches - return if direct_visibility? || marked_for_mass_destruction? + return if direct_visibility? account&.decrement_count!(:statuses_count) reblog&.decrement_count!(:reblogs_count) if reblog? @@ -440,7 +432,7 @@ class Status < ApplicationRecord def unlink_from_conversations return unless direct_visibility? - mentioned_accounts = mentions.includes(:account).map(&:account) + mentioned_accounts = (association(:mentions).loaded? ? mentions : mentions.includes(:account)).map(&:account) inbox_owners = mentioned_accounts.select(&:local?) + (account.local? ? [account] : []) inbox_owners.each do |inbox_owner| |