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
21
# 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({}) { |uuid_item, store| store[uuid_item[0, 2]] = uuid_item[-1] }
  extract_receptacles_from_labware
end

Instance Method Details

#find(klass, uuid) ⇒ Object


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

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