rails_error_dashboard 0.1.22 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b04467a3dfb4cb2500b3dd7cdcc8ab157e54dccbd9630f1333a2aae81e0d714
4
- data.tar.gz: ffadf9eefd995500948a560f04c394adf1c005b892f7e4f23cd80ac5a7b9f4c8
3
+ metadata.gz: e8ebc7a75413a15752df2dc4a425f0c2dc046480e92d394d68212646360787e9
4
+ data.tar.gz: c4174fc14f0e8c9ca2da761bf7895f0ff5d3cf85d99470b31705dc748d9083f2
5
5
  SHA512:
6
- metadata.gz: 46997287677b84461147c6ac344927a4e38d90f52da72de5069e48afe3072bc6b04d88936dc28e3c8b7c50fe47c065980286e8cbf98b3388756a8ae29a57b8f0
7
- data.tar.gz: 93f7d23fe4bdf2a6fd5d62d488108e63423167b77af171e4ab42a9203c9d220010f26a34c339edda553efdcd083d54761c4d8bb0b303400b5c4a9c615775a2e3
6
+ metadata.gz: 33ab7875fcef261cc93f8af9ac7a7203e5b1c49a708baf247e63c7c2c9e40932d1fa21eb25c34f8b1f0d4e4f63dff3f1fdbb43f0f2b7b252575de6aaccd9cd08
7
+ data.tar.gz: 9213caf3f27b27b6a04e0dc198da8e45c7561734f6c5f14f8ccbaf150f17015b3e6693c05a14b4c73e47674ca6d12ae90f75097167e65ec80d47f03e7de9e507
@@ -1,6 +1,6 @@
1
1
  module RailsErrorDashboard
2
2
  class Application < ActiveRecord::Base
3
- self.table_name = 'rails_error_dashboard_applications'
3
+ self.table_name = "rails_error_dashboard_applications"
4
4
 
5
5
  # Associations
6
6
  has_many :error_logs, dependent: :restrict_with_error
@@ -12,10 +12,23 @@ module RailsErrorDashboard
12
12
  scope :ordered_by_name, -> { order(:name) }
13
13
 
14
14
  # Class method for finding or creating with caching
15
+ # Only caches successful finds, not creates (to avoid caching nil on creation failures)
15
16
  def self.find_or_create_by_name(name)
16
- Rails.cache.fetch("error_dashboard/application/#{name}", expires_in: 1.hour) do
17
- find_or_create_by!(name: name)
17
+ # Try to find in cache or database first
18
+ cached = Rails.cache.read("error_dashboard/application/#{name}")
19
+ return cached if cached
20
+
21
+ # Try to find existing
22
+ found = find_by(name: name)
23
+ if found
24
+ Rails.cache.write("error_dashboard/application/#{name}", found, expires_in: 1.hour)
25
+ return found
18
26
  end
27
+
28
+ # Create if not found (don't cache until successful)
29
+ created = create!(name: name)
30
+ Rails.cache.write("error_dashboard/application/#{name}", created, expires_in: 1.hour)
31
+ created
19
32
  end
20
33
 
21
34
  # Instance methods
@@ -1,3 +1,3 @@
1
1
  module RailsErrorDashboard
2
- VERSION = "0.1.22"
2
+ VERSION = "0.1.23"
3
3
  end
@@ -10,11 +10,11 @@ namespace :error_dashboard do
10
10
  # Use single SQL query with aggregates to avoid N+1 queries
11
11
  # This fetches all app data + error counts in one query instead of 6N queries
12
12
  apps = RailsErrorDashboard::Application
13
- .select('rails_error_dashboard_applications.*')
14
- .select('COUNT(rails_error_dashboard_error_logs.id) as total_errors')
15
- .select('COALESCE(SUM(CASE WHEN NOT rails_error_dashboard_error_logs.resolved THEN 1 ELSE 0 END), 0) as unresolved_errors')
16
- .joins('LEFT JOIN rails_error_dashboard_error_logs ON rails_error_dashboard_error_logs.application_id = rails_error_dashboard_applications.id')
17
- .group('rails_error_dashboard_applications.id')
13
+ .select("rails_error_dashboard_applications.*")
14
+ .select("COUNT(rails_error_dashboard_error_logs.id) as total_errors")
15
+ .select("COALESCE(SUM(CASE WHEN NOT rails_error_dashboard_error_logs.resolved THEN 1 ELSE 0 END), 0) as unresolved_errors")
16
+ .joins("LEFT JOIN rails_error_dashboard_error_logs ON rails_error_dashboard_error_logs.application_id = rails_error_dashboard_applications.id")
17
+ .group("rails_error_dashboard_applications.id")
18
18
  .order(:name)
19
19
 
20
20
  if apps.empty?
@@ -27,9 +27,9 @@ namespace :error_dashboard do
27
27
  puts "\n#{apps.count} application(s) registered:\n\n"
28
28
 
29
29
  # Calculate column widths using aggregated data (no additional queries)
30
- name_width = [apps.map(&:name).map(&:length).max, 20].max
31
- total_width = [apps.map(&:total_errors).map(&:to_s).map(&:length).max, 5].max
32
- unresolved_width = [apps.map(&:unresolved_errors).map(&:to_s).map(&:length).max, 10].max
30
+ name_width = [ apps.map(&:name).map(&:length).max, 20 ].max
31
+ total_width = [ apps.map(&:total_errors).map(&:to_s).map(&:length).max, 5 ].max
32
+ unresolved_width = [ apps.map(&:unresolved_errors).map(&:to_s).map(&:length).max, 10 ].max
33
33
 
34
34
  # Print header
35
35
  printf "%-#{name_width}s %#{total_width}s %#{unresolved_width}s %s\n",
@@ -62,9 +62,9 @@ namespace :error_dashboard do
62
62
 
63
63
  desc "Backfill application_id for existing errors"
64
64
  task backfill_application: :environment do
65
- app_name = ENV['APP_NAME'] || ENV['APPLICATION_NAME'] ||
65
+ app_name = ENV["APP_NAME"] || ENV["APPLICATION_NAME"] ||
66
66
  (defined?(Rails) && Rails.application.class.module_parent_name) ||
67
- 'Legacy Application'
67
+ "Legacy Application"
68
68
 
69
69
  puts "\n" + "=" * 80
70
70
  puts "RAILS ERROR DASHBOARD - BACKFILL APPLICATION"
@@ -94,7 +94,7 @@ namespace :error_dashboard do
94
94
  print "\nProceed with backfill? (y/N): "
95
95
  confirmation = $stdin.gets.chomp.downcase
96
96
 
97
- unless confirmation == 'y' || confirmation == 'yes'
97
+ unless confirmation == "y" || confirmation == "yes"
98
98
  puts "\n✗ Backfill cancelled"
99
99
  puts "\n" + "=" * 80 + "\n"
100
100
  next
@@ -125,8 +125,8 @@ namespace :error_dashboard do
125
125
 
126
126
  desc "Show application statistics and health metrics"
127
127
  task app_stats: :environment do
128
- app_id = ENV['APP_ID']
129
- app_name = ENV['APP_NAME']
128
+ app_id = ENV["APP_ID"]
129
+ app_name = ENV["APP_NAME"]
130
130
 
131
131
  puts "\n" + "=" * 80
132
132
  puts "RAILS ERROR DASHBOARD - APPLICATION STATISTICS"
@@ -135,16 +135,16 @@ namespace :error_dashboard do
135
135
  # Find application
136
136
  app = if app_id
137
137
  RailsErrorDashboard::Application.find_by(id: app_id)
138
- elsif app_name
138
+ elsif app_name
139
139
  RailsErrorDashboard::Application.find_by(name: app_name)
140
- else
140
+ else
141
141
  puts "\n✗ Please specify APP_ID or APP_NAME"
142
142
  puts "\nExamples:"
143
143
  puts " rails error_dashboard:app_stats APP_NAME='My App'"
144
144
  puts " rails error_dashboard:app_stats APP_ID=1"
145
145
  puts "\n" + "=" * 80 + "\n"
146
146
  next
147
- end
147
+ end
148
148
 
149
149
  unless app
150
150
  puts "\n✗ Application not found"
@@ -202,11 +202,11 @@ namespace :error_dashboard do
202
202
  time_ago = Time.current - error.occurred_at
203
203
  time_str = if time_ago < 3600
204
204
  "#{(time_ago / 60).to_i}m ago"
205
- elsif time_ago < 86400
205
+ elsif time_ago < 86400
206
206
  "#{(time_ago / 3600).to_i}h ago"
207
- else
207
+ else
208
208
  "#{(time_ago / 86400).to_i}d ago"
209
- end
209
+ end
210
210
  puts " • #{error.error_type} (#{time_str}) - #{error.message.truncate(50)}"
211
211
  end
212
212
  end
@@ -216,8 +216,8 @@ namespace :error_dashboard do
216
216
 
217
217
  desc "Clean up old resolved errors"
218
218
  task cleanup_resolved: :environment do
219
- days = ENV['DAYS']&.to_i || 90
220
- app_name = ENV['APP_NAME']
219
+ days = ENV["DAYS"]&.to_i || 90
220
+ app_name = ENV["APP_NAME"]
221
221
 
222
222
  puts "\n" + "=" * 80
223
223
  puts "RAILS ERROR DASHBOARD - CLEANUP RESOLVED ERRORS"
@@ -225,7 +225,7 @@ namespace :error_dashboard do
225
225
  puts "\nCleaning up resolved errors older than #{days} days"
226
226
 
227
227
  scope = RailsErrorDashboard::ErrorLog.resolved
228
- .where('resolved_at < ?', days.days.ago)
228
+ .where("resolved_at < ?", days.days.ago)
229
229
 
230
230
  if app_name
231
231
  app = RailsErrorDashboard::Application.find_by(name: app_name)
@@ -252,7 +252,7 @@ namespace :error_dashboard do
252
252
  print "\nProceed with deletion? (y/N): "
253
253
  confirmation = $stdin.gets.chomp.downcase
254
254
 
255
- unless confirmation == 'y' || confirmation == 'yes'
255
+ unless confirmation == "y" || confirmation == "yes"
256
256
  puts "\n✗ Cleanup cancelled"
257
257
  puts "\n" + "=" * 80 + "\n"
258
258
  next
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_error_dashboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anjan Jagirdar
@@ -386,7 +386,7 @@ metadata:
386
386
  source_code_uri: https://github.com/AnjanJ/rails_error_dashboard
387
387
  changelog_uri: https://github.com/AnjanJ/rails_error_dashboard/blob/main/CHANGELOG.md
388
388
  post_install_message: "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n
389
- \ Rails Error Dashboard v0.1.22\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n\U0001F195
389
+ \ Rails Error Dashboard v0.1.23\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n\U0001F195
390
390
  First time? Quick start:\n rails generate rails_error_dashboard:install\n rails
391
391
  db:migrate\n # Add to config/routes.rb:\n mount RailsErrorDashboard::Engine
392
392
  => '/error_dashboard'\n\n\U0001F504 Upgrading from v0.1.x?\n rails db:migrate\n