Tidy up homepage and navigation
This commit is contained in:
@@ -29,6 +29,8 @@ class NetworkRange < ApplicationRecord
|
||||
scope :vpn, -> { where(is_vpn: true) }
|
||||
scope :user_created, -> { where(source: 'user_created') }
|
||||
scope :api_imported, -> { where(source: 'api_imported') }
|
||||
scope :with_events, -> { where("events_count > 0") }
|
||||
scope :most_active, -> { order(events_count: :desc) }
|
||||
|
||||
# Callbacks
|
||||
before_validation :set_default_source
|
||||
@@ -237,9 +239,10 @@ class NetworkRange < ApplicationRecord
|
||||
cidr.to_s.gsub('/', '_')
|
||||
end
|
||||
|
||||
# Analytics methods
|
||||
# Analytics methods - events_count is now a counter cache column maintained by database triggers
|
||||
# This is much more performant than the previous implementation that did complex network queries
|
||||
def events_count
|
||||
Event.where(ip_address: child_ranges.pluck(:network_address) + [network_address]).count
|
||||
self[:events_count] || 0
|
||||
end
|
||||
|
||||
def recent_events(limit: 100)
|
||||
|
||||
Reference in New Issue
Block a user