Class: Bullematic::Notifier
- Inherits:
-
Object
- Object
- Bullematic::Notifier
- Defined in:
- lib/bullematic/notifier.rb,
sig/generated/bullematic/notifier.rbs
Class Method Summary collapse
-
.compatible? ⇒ Boolean
: () -> bool.
- .process_notifications(context_id: nil) ⇒ void
-
.setup ⇒ void
: () -> void.
Class Method Details
.compatible? ⇒ Boolean
: () -> bool
17 18 19 20 21 22 23 |
# File 'lib/bullematic/notifier.rb', line 17 def compatible? return false unless defined?(Bullet) Bullet.respond_to?(:notification?, true) && Bullet.respond_to?(:notification_collector, true) && !defined?(Bullet::Notification::NPlusOneQuery).nil? end |
.process_notifications(context_id: nil) ⇒ void
This method returns an undefined value.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bullematic/notifier.rb', line 27 def process_notifications(context_id: nil) return unless compatible? && Bullet.notification? context_id ||= Object.new.object_id config = Bullematic.configuration if config&.logger && config.debug config.logger.debug "[Bullematic] Processing notifications..." end collector = Bullet.send(:notification_collector) return unless collector&.respond_to?(:collection) notifications = 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 = [notification_set] unless notification_set.respond_to?(:each) notification_set.each do |notification| type = process_notification(notification, context_id) n_plus_one_count += 1 if type == :n_plus_one unused_eager_loading_count += 1 if type == :unused_eager_loading end end when Enumerable notifications.each do |notification| type = process_notification(notification, context_id) n_plus_one_count += 1 if type == :n_plus_one unused_eager_loading_count += 1 if type == :unused_eager_loading 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 rescue StandardError => error begin Bullematic.configuration&.logger&.warn( "[Bullematic] Failed to process Bullet notifications: #{error.}" ) rescue StandardError nil end end |
.setup ⇒ void
This method returns an undefined value.
: () -> void
8 9 10 11 12 13 14 |
# File 'lib/bullematic/notifier.rb', line 8 def setup return if compatible? Bullematic.configuration&.logger&.warn( "[Bullematic] Disabled: Bullet notification API is unavailable" ) end |