-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Denormalize event type for request and event logs #829
base: master
Are you sure you want to change the base?
Conversation
25135c0
to
d0ebf37
Compare
d0ebf37
to
d78f333
Compare
db/migrate/20240501124926_add_event_type_event_to_request_logs.rb
Outdated
Show resolved
Hide resolved
db/migrate/20240501124919_add_event_type_event_to_event_logs.rb
Outdated
Show resolved
Hide resolved
d78f333
to
5dde815
Compare
has_one :event_log, | ||
inverse_of: :request_log | ||
|
||
has_environment | ||
has_account | ||
|
||
denormalizes :event, from: :event_type, prefix: :event_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be denormalizing event_type_id
from event_log
too? Would solve for the race condition touched on here.
@@ -22,6 +23,9 @@ class EventLog < ApplicationRecord | |||
has_environment | |||
has_account | |||
|
|||
denormalizes :event, from: :event_type, prefix: :event_type | |||
denormalizes :event_type_id, to: :request_log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible race condition here since there's no guarantee an event log will be inserted after a request log. Need to rethink this (and write appropriate tests).
@@ -11,12 +12,15 @@ class RequestLog < ApplicationRecord | |||
|
|||
belongs_to :requestor, polymorphic: true, optional: true | |||
belongs_to :resource, polymorphic: true, optional: true | |||
belongs_to :event_type, optional: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this being set?
Part 1 of 4. Improves performance for Dashboard metrics.
Prerequisites
Post deploy
Part 2 (in order of operations)
event_type_event
fromevent_types
toevent_logs
.NOT NULL
constraint toevent_logs.event_type_event
.event_logs.event_type_event
.VACUUM ANALYZE event_logs
.Part 3 (in order of operations)
event_type_id
andevent_type_event
fromevent_logs
torequest_logs
.NOT NULL
constraints torequest_logs.event_type_id
andrequest_logs.event_type_event
.request_logs.event_type_id
andrequest_logs.event_type_event
.VACUUM ANALYZE request_logs
.Part 4
EventLog.for_event_type
to use denormalizedevent_type_event
column for strings.RequestLog.for_event_type
to use denormalizedevent_type_event
column.