Class: TransferRequestCollection::UuidCache

Inherits:
Object
  • Object
show all
Defined in:
app/models/transfer_request_collection.rb

Overview

Extracts all the uuids from the query and caches the associated information Greatly improves performance.

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ UuidCache

Returns a new instance of UuidCache.


13
14
15
16
17
18
19
20
# File 'app/models/transfer_request_collection.rb', line 13

def initialize(parameters)
  uuids = parameters.flat_map(&:values).select { |v| v.is_a?(String) && Uuid::ValidRegexp.match?(v) }
  @cache = Uuid.where(external_id: uuids).pluck(:external_id, :resource_type,
                                                :resource_id).each_with_object({}) do |uuid_item, store|
    store[uuid_item[0, 2]] = uuid_item[-1]
  end
  extract_receptacles_from_labware
end

Instance Method Details

#find(klass, uuid) ⇒ Object


22
23
24
# File 'app/models/transfer_request_collection.rb', line 22

def find(klass, uuid)
  @cache[[uuid, klass.base_class.name]]
end