mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 06:58:31 +08:00
PERF: Reduce DB queries when serializing ignore/mute information (#8629)
* PERF: Cache ignored and muted user ids in the current_user object * PERF: Avoid DB queries when checking ignore/mute permission in guardian
This commit is contained in:
@ -83,6 +83,9 @@ class User < ActiveRecord::Base
|
||||
has_many :muted_user_records, class_name: 'MutedUser'
|
||||
has_many :muted_users, through: :muted_user_records
|
||||
|
||||
has_many :ignored_user_records, class_name: 'IgnoredUser'
|
||||
has_many :ignored_users, through: :ignored_user_records
|
||||
|
||||
has_many :api_keys, dependent: :destroy
|
||||
|
||||
has_many :push_subscriptions, dependent: :destroy
|
||||
@ -468,9 +471,19 @@ class User < ActiveRecord::Base
|
||||
@unread_total_notifications = nil
|
||||
@unread_pms = nil
|
||||
@user_fields = nil
|
||||
@ignored_user_ids = nil
|
||||
@muted_user_ids = nil
|
||||
super
|
||||
end
|
||||
|
||||
def ignored_user_ids
|
||||
@ignored_user_ids ||= ignored_users.pluck(:id)
|
||||
end
|
||||
|
||||
def muted_user_ids
|
||||
@muted_user_ids ||= muted_users.pluck(:id)
|
||||
end
|
||||
|
||||
def unread_notifications_of_type(notification_type)
|
||||
# perf critical, much more efficient than AR
|
||||
sql = <<~SQL
|
||||
|
Reference in New Issue
Block a user