Move status counters to separate table, count replies (#8104)
* Move status counters to separate table, count replies * Migration to remove old counter columns from statuses table * Fix schema file
This commit is contained in:
parent
018a9e4e7f
commit
8e111b753a
10 changed files with 142 additions and 32 deletions
|
@ -32,20 +32,11 @@ class Favourite < ApplicationRecord
|
|||
private
|
||||
|
||||
def increment_cache_counters
|
||||
if association(:status).loaded?
|
||||
status.update_attribute(:favourites_count, status.favourites_count + 1)
|
||||
else
|
||||
Status.where(id: status_id).update_all('favourites_count = COALESCE(favourites_count, 0) + 1')
|
||||
end
|
||||
status.increment_count!(:favourites_count)
|
||||
end
|
||||
|
||||
def decrement_cache_counters
|
||||
return if association(:status).loaded? && (status.marked_for_destruction? || status.marked_for_mass_destruction?)
|
||||
|
||||
if association(:status).loaded?
|
||||
status.update_attribute(:favourites_count, [status.favourites_count - 1, 0].max)
|
||||
else
|
||||
Status.where(id: status_id).update_all('favourites_count = GREATEST(COALESCE(favourites_count, 0) - 1, 0)')
|
||||
end
|
||||
status.decrement_count!(:favourites_count)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue