Skip to content

Commit

Permalink
Speed up MiqEventDefinitionSet.seed
Browse files Browse the repository at this point in the history
MiqEventDefinitionSet is static union. It is dumb to use 13 selects
on every start-up (during the db lock) to ensure that the union is
in place.

On my system, the `10_000.times { MiqEventDefinitionSet.seed }` gives:

:kiss: |  rows  | selects | time |  %
-------| ------ | ------- | ---- | ----
Before | 130000 |  130000 | 123s | 100%
After  | 130000 |   10000 |  34s |  27%
  • Loading branch information
isimluk committed Apr 11, 2017
1 parent c5956c8 commit ad4c647
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/miq_event_definition_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ class MiqEventDefinitionSet < ApplicationRecord
acts_as_miq_set

def self.seed
existing = all.group_by(&:name)
CSV.foreach(fixture_path, :headers => true, :skip_lines => /^#/) do |csv_row|
set = csv_row.to_hash

rec = find_by(:name => set['name'])
rec = existing[set['name']].try(:first)
if rec.nil?
_log.info("Creating [#{set['name']}]")
create!(set)
Expand Down

0 comments on commit ad4c647

Please sign in to comment.