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

[Performance] MiqSearch.seed #15666

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions app/models/miq_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,32 @@ def self.descriptions

FIXTURE_DIR = File.join(Rails.root, "db/fixtures")
def self.seed
searches = where("name like 'default%'").index_by { |ms| "#{ms.name}-#{ms.db}" }
fixture_file = File.join(FIXTURE_DIR, "miq_searches.yml")
slist = YAML.load_file(fixture_file) if File.exist?(fixture_file)
slist ||= []

slist.group_by { |s| [s['attributes']['name'], s['attributes']['db']] }.each do |(name, db), dups|
_log.warn("duplicate entry for db=#{db} name=#{name}") if dups.size > 1
end
slist.each do |search|
attrs = search['attributes']
name = attrs['name']
db = attrs['db']

rec = find_by(:name => name, :db => db)
rec = searches["#{name}-#{db}"]
if rec.nil?
_log.info("Creating [#{name}]")
create!(attrs)
searches["#{name}-#{db}"] = create!(attrs)
else
# Avoid undoing user changes made to enable/disable default searches which is held in the search_key column
attrs.delete('search_key')

# properly compare filter
filter = attrs.delete('filter')
rec.filter = filter if rec.filter.exp != filter.exp
rec.attributes = attrs
rec.save!

rec.save! if rec.changed?
end
end
end
Expand Down
21 changes: 0 additions & 21 deletions db/fixtures/miq_searches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,6 @@
value: "on"
search_type: default
db: Host
- attributes:
name: default_Status / Running
description: Status / Running
filter: !ruby/object:MiqExpression
exp:
INCLUDES:
field: Host-power_state
value: "on"
search_type: default
db: Host
- attributes:
name: default_Status / Stopped
description: Status / Stopped
Expand Down Expand Up @@ -379,17 +369,6 @@
value: "on"
search_type: default
db: Host
- attributes:
name: default_Status / Stopped
description: Status / Stopped
filter: !ruby/object:MiqExpression
exp:
not:
INCLUDES:
field: Host-power_state
value: "on"
search_type: default
db: Host
- attributes:
name: default_Store Type / NFS
description: Store Type / NFS
Expand Down