mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 10:55:49 +08:00
PERF: much faster Badge.ensure_consistency
This commit is contained in:
parent
e6f22725c8
commit
3d406b047c
@ -137,7 +137,19 @@ class Badge < ActiveRecord::Base
|
|||||||
AND user_badges.id = ub.id
|
AND user_badges.id = ub.id
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
Badge.find_each(&:reset_grant_count!)
|
exec_sql <<-SQL.squish
|
||||||
|
WITH X AS (
|
||||||
|
SELECT badge_id
|
||||||
|
, COUNT(user_id) users
|
||||||
|
FROM user_badges
|
||||||
|
GROUP BY badge_id
|
||||||
|
)
|
||||||
|
UPDATE badges
|
||||||
|
SET grant_count = X.users
|
||||||
|
FROM X
|
||||||
|
WHERE id = X.badge_id
|
||||||
|
AND grant_count <> X.users
|
||||||
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
def awarded_for_trust_level?
|
def awarded_for_trust_level?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user