Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/bullematic/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,51 @@ def setup
def process_notifications
return unless defined?(Bullet) && Bullet.notification?

config = Bullematic.configuration
if config&.logger && config.debug
config.logger.debug "[Bullematic] Processing notifications..."
end

notifications = Bullet.send(:notification_collector)&.collection

if config&.logger && config.debug
config.logger.debug "[Bullematic] Notifications collection type: #{notifications.class}"
config.logger.debug "[Bullematic] Notifications count: #{notifications.respond_to?(:size) ? notifications.size : 'unknown'}"
end

n_plus_one_count = 0
unused_eager_loading_count = 0

case notifications
when Hash
notifications.each_value do |notification_set|
notification_set.each do |notification|
if notification.is_a?(Bullet::Notification::NPlusOneQuery)
n_plus_one_count += 1
process_n_plus_one(notification)
elsif notification.is_a?(Bullet::Notification::UnusedEagerLoading)
unused_eager_loading_count += 1
process_unused_eager_loading(notification)
end
end
end
when Enumerable
notifications.each do |notification|
if notification.is_a?(Bullet::Notification::NPlusOneQuery)
n_plus_one_count += 1
process_n_plus_one(notification)
elsif notification.is_a?(Bullet::Notification::UnusedEagerLoading)
unused_eager_loading_count += 1
process_unused_eager_loading(notification)
end
end
end

if config&.logger && config.debug
config.logger.debug "[Bullematic] Processed #{n_plus_one_count} N+1 notifications"
config.logger.debug "[Bullematic] Processed #{unused_eager_loading_count} UnusedEagerLoading notifications"
config.logger.debug "[Bullematic] Detection queue size: #{Fixer.detection_queue.size}"
end
end

private
Expand Down
Loading