-
Notifications
You must be signed in to change notification settings - Fork 897
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
Avoid dozens of extra selects in seed_default_events #14722
Avoid dozens of extra selects in seed_default_events #14722
Conversation
4bf290c
to
8fdcefe
Compare
app/models/miq_event_definition.rb
Outdated
@@ -123,6 +123,7 @@ def self.seed | |||
end | |||
|
|||
def self.seed_default_events | |||
event_sets = MiqEventDefinitionSet.all.group_by(&:name) |
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.
isn't it operation on Array ?
what about to use sql ?
MiqEventDefinitionSet.group(:name)
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.
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.
agh yes, I am sorry, it is not same, 😳 please ignore my comment
app/models/miq_event_definition.rb
Outdated
@@ -123,6 +123,7 @@ def self.seed | |||
end | |||
|
|||
def self.seed_default_events | |||
event_sets = MiqEventDefinitionSet.all.group_by(&:name) |
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.
Is .index_by
a better choice than .group_by
? Especially since you are doing a .first
below?
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.
Amended. Great suggestion! Thanks!
and use common before section.
before calling seed_default_events, that will enable us to be more strict within the method -> more validations for db/fixtures Fail early, fail fast.
MiqEventDefinitionSet is static union. It is inefficient to use multiple selects instead of a single one. On my system `100.times { MiqEventDefinition.seed_default_events }` gives :gear: | rows | selects | time | % ------ | ----- | ------- | ---- | --- Before | 16900 | 16900 | 204s | 100% After | 1300 | 100 | 93s | 45%
8fdcefe
to
76d4220
Compare
Checked commits isimluk/manageiq@0699939~...76d4220 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
MiqEventDefinitionSet is static union. It is inefficient to use multiple selects instead of a single one.
On my system
100.times { MiqEventDefinition.seed_default_events }
gives