Method: Vines::Services::CouchModels::System.find_by_names
- Defined in:
- lib/vines/services/storage/couchdb/system.rb
.find_by_names(names) ⇒ Object
Return an Array of Systems with the given names. This method efficiently bulk loads systems and their services much more quickly than loading systems one by one. Note that the systems returned by this method do not have their ohai data loaded because it’s expensive.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/vines/services/storage/couchdb/system.rb', line 120 def self.find_by_names(names) keys = names.map {|name| [1, name.downcase] } rows = database.view(VIEW_NAME, reduce: false, keys: keys)['rows'] rescue [] ids = rows.map {|row| row['value'] }.uniq services = Service.all.keys(ids).to_a by_id = Hash[services.map {|s| [s.id, s] }] by_name = Hash.new do |h, k| h[k] = System.new(id: "system:#{k}").tap do |system| system.services = [] end end rows.each do |row| name = row['key'][1] service = by_id[row['value']] by_name[name].services << service end by_name.values end |