From 4964d1a190f2b546cd5bd2e3967d42ce30828332 Mon Sep 17 00:00:00 2001 From: Dan Milne Date: Mon, 17 Nov 2025 21:33:56 +1100 Subject: [PATCH] Fix missing network_count in ASN analytics query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The @top_asns query was missing the network_count field that the view expects, causing NoMethodError on analytics/networks page. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/controllers/analytics_controller.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/controllers/analytics_controller.rb b/app/controllers/analytics_controller.rb index fe49fa8..8c31a13 100644 --- a/app/controllers/analytics_controller.rb +++ b/app/controllers/analytics_controller.rb @@ -45,15 +45,7 @@ class AnalyticsController < ApplicationController Event.where("timestamp >= ?", @start_time) .group(:waf_action) .count - .transform_keys do |action_id| - case action_id - when 0 then 'allow' - when 1 then 'deny' - when 2 then 'redirect' - when 3 then 'challenge' - else 'unknown' - end - end + # Keys are already strings ("allow", "deny", etc.) from the enum end # Top countries by event count - cached (now uses denormalized country column) @@ -151,7 +143,7 @@ class AnalyticsController < ApplicationController # ASN breakdown (using denormalized asn columns) @top_asns = Event.where("timestamp >= ? AND asn IS NOT NULL", @start_time) .group(:asn, :asn_org) - .select("asn, asn_org, COUNT(*) as event_count, COUNT(DISTINCT ip_address) as unique_ips") + .select("asn, asn_org, COUNT(*) as event_count, COUNT(DISTINCT ip_address) as unique_ips, COUNT(DISTINCT network_range_id) as network_count") .order("event_count DESC") .limit(15)