mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 06:28:03 +08:00
PERF: improve performance of consistency query
This commit is contained in:
parent
8e9a8472f4
commit
1f062ae2fd
|
@ -95,7 +95,14 @@ class CategoryUser < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.ensure_consistency!
|
||||
exec_sql("DELETE FROM category_users WHERE user_id NOT IN (SELECT id FROM users)")
|
||||
exec_sql <<SQL
|
||||
DELETE FROM category_users
|
||||
WHERE user_id IN (
|
||||
SELECT cu.user_id FROM category_users cu
|
||||
LEFT JOIN users u ON u.id = cu.user_id
|
||||
WHERE u.id IS NULL
|
||||
)
|
||||
SQL
|
||||
end
|
||||
|
||||
private_class_method :apply_default_to_topic, :remove_default_from_topic
|
||||
|
|
Loading…
Reference in New Issue
Block a user