Class: RailsErrorDashboard::Application

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/rails_error_dashboard/application.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_or_create_by_name(name) ⇒ Object

Class method for finding or creating with caching Only caches successful finds, not creates (to avoid caching nil on creation failures)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/rails_error_dashboard/application.rb', line 16

def self.find_or_create_by_name(name)
  # Try to find in cache or database first
  cached = Rails.cache.read("error_dashboard/application/#{name}")
  return cached if cached

  # Try to find existing
  found = find_by(name: name)
  if found
    Rails.cache.write("error_dashboard/application/#{name}", found, expires_in: 1.hour)
    return found
  end

  # Create if not found (don't cache until successful)
  created = create!(name: name)
  Rails.cache.write("error_dashboard/application/#{name}", created, expires_in: 1.hour)
  created
end

Instance Method Details

#error_countObject

Instance methods



35
36
37
# File 'app/models/rails_error_dashboard/application.rb', line 35

def error_count
  error_logs.count
end

#unresolved_error_countObject



39
40
41
# File 'app/models/rails_error_dashboard/application.rb', line 39

def unresolved_error_count
  error_logs.unresolved.count
end