get rid of N+1 query in `notification_count` method

This commit is contained in:
Andreas Nedbal 2022-12-18 02:23:21 +01:00 committed by Andreas Nedbal
parent 5a0e42fe66
commit 19e5837ce5
1 changed files with 3 additions and 4 deletions

View File

@ -22,11 +22,10 @@ module ApplicationHelper
def notification_count def notification_count
return 0 unless user_signed_in? return 0 unless user_signed_in?
count = Notification.for(current_user).where(new: true) count = Notification.for(current_user).where(new: true).pluck(:id).size
return nil if count.nil? return nil unless count.positive?
return nil unless count.count.positive?
count.count count
end end
def privileged?(user) def privileged?(user)