Class: RailsErrorDashboard::Queries::AnalyticsStats
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Queries::AnalyticsStats
- Defined in:
- lib/rails_error_dashboard/queries/analytics_stats.rb
Overview
Query: Fetch analytics statistics for charts and trends This is a read operation that aggregates error data over time
Class Method Summary collapse
Instance Method Summary collapse
- #cache_key ⇒ Object
- #call ⇒ Object
-
#initialize(days = 30) ⇒ AnalyticsStats
constructor
A new instance of AnalyticsStats.
Constructor Details
#initialize(days = 30) ⇒ AnalyticsStats
Returns a new instance of AnalyticsStats.
12 13 14 15 |
# File 'lib/rails_error_dashboard/queries/analytics_stats.rb', line 12 def initialize(days = 30) @days = days @start_date = days.days.ago end |
Class Method Details
.call(days = 30) ⇒ Object
8 9 10 |
# File 'lib/rails_error_dashboard/queries/analytics_stats.rb', line 8 def self.call(days = 30) new(days).call end |
Instance Method Details
#cache_key ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rails_error_dashboard/queries/analytics_stats.rb', line 37 def cache_key # Cache key includes: # - Query class name # - Days parameter (different time ranges = different caches) # - Last error update timestamp (auto-invalidates when errors change) # - Start date (ensures correct time window) [ "analytics_stats", @days, ErrorLog.maximum(:updated_at)&.to_i || 0, @start_date.to_date.to_s ].join("/") end |
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rails_error_dashboard/queries/analytics_stats.rb', line 17 def call # Cache analytics data for 5 minutes to reduce database load # Cache key includes days parameter and last error update timestamp Rails.cache.fetch(cache_key, expires_in: 5.minutes) do { days: @days, error_stats: error_statistics, errors_over_time: errors_over_time, errors_by_type: errors_by_type, errors_by_platform: errors_by_platform, errors_by_hour: errors_by_hour, top_users: top_affected_users, resolution_rate: resolution_rate, mobile_errors: mobile_errors_count, api_errors: api_errors_count, pattern_insights: pattern_insights } end end |