Commit 0d5434b3ade03a45122be60d2baa26b98da3222b

Authored by Stephen Crosby
1 parent 8cf20c3e
Exists in master and in 1 other branch production

cache app on notice

Notices always have an app API key when they arrive at Errbit, so it
makes sense to cache the app id onto the notice object. This will allow
for more efficient refingerprinting and reporting down the road.
app/models/error_report.rb
@@ -65,6 +65,7 @@ class ErrorReport @@ -65,6 +65,7 @@ class ErrorReport
65 65
66 def make_notice 66 def make_notice
67 @notice = Notice.new( 67 @notice = Notice.new(
  68 + app: app,
68 message: message, 69 message: message,
69 error_class: error_class, 70 error_class: error_class,
70 backtrace: backtrace, 71 backtrace: backtrace,
app/models/notice.rb
@@ -12,8 +12,9 @@ class Notice @@ -12,8 +12,9 @@ class Notice
12 field :framework 12 field :framework
13 field :error_class 13 field :error_class
14 delegate :lines, :to => :backtrace, :prefix => true 14 delegate :lines, :to => :backtrace, :prefix => true
15 - delegate :app, :problem, :to => :err 15 + delegate :problem, :to => :err
16 16
  17 + belongs_to :app
17 belongs_to :err 18 belongs_to :err
18 belongs_to :backtrace, :index => true 19 belongs_to :backtrace, :index => true
19 20
db/migrate/20150926035420_cache_app_on_notice.rb 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +class CacheAppOnNotice < Mongoid::Migration
  2 + def self.up
  3 + Notice.no_timeout.each do |n|
  4 + n.app_id = n.try(:err).try(:problem).try(:app_id)
  5 + n.save!
  6 + end
  7 + end
  8 +
  9 + def self.down
  10 + end
  11 +end
spec/fabricators/err_fabricator.rb
@@ -4,6 +4,7 @@ Fabricator :err do @@ -4,6 +4,7 @@ Fabricator :err do
4 end 4 end
5 5
6 Fabricator :notice do 6 Fabricator :notice do
  7 + app
7 err 8 err
8 message 'FooError: Too Much Bar' 9 message 'FooError: Too Much Bar'
9 backtrace 10 backtrace