Skip to content
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

Merged
merged 3 commits into from
Apr 20, 2017

Conversation

isimluk
Copy link
Member

@isimluk isimluk commented Apr 11, 2017

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

⚙️ rows selects time %
Before 16900 16900 204s 100%
After 1300 100 93s 45%

@isimluk isimluk force-pushed the speed-up-miq_event_definition-seeds-2 branch 2 times, most recently from 4bf290c to 8fdcefe Compare April 11, 2017 11:39
@@ -123,6 +123,7 @@ def self.seed
end

def self.seed_default_events
event_sets = MiqEventDefinitionSet.all.group_by(&:name)
Copy link
Contributor

@lpichler lpichler Apr 11, 2017

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work :-(

does-not-fly

Copy link
Contributor

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

@@ -123,6 +123,7 @@ def self.seed
end

def self.seed_default_events
event_sets = MiqEventDefinitionSet.all.group_by(&:name)
Copy link
Member

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?

Copy link
Member Author

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%
@isimluk isimluk force-pushed the speed-up-miq_event_definition-seeds-2 branch from 8fdcefe to 76d4220 Compare April 18, 2017 07:53
@miq-bot
Copy link
Member

miq-bot commented Apr 18, 2017

Checked commits isimluk/manageiq@0699939~...76d4220 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks good. 🍪

@kbrock kbrock merged commit 4ac1708 into ManageIQ:master Apr 20, 2017
@isimluk isimluk deleted the speed-up-miq_event_definition-seeds-2 branch April 20, 2017 12:28
@kbrock kbrock added this to the Sprint 59 Ending Apr 24, 2017 milestone Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants