Class: Valkyrie::Persistence::BufferedPersister

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/persistence/buffered_persister.rb

Overview

Implements the DataMapper Pattern to proxy another Metadata Persister

Provides with_buffer to send multiple updates at one time to the proxied persister

In some cases this will realize performance gains

Examples:

buffered_persister.with_buffer do |persist, buffer|
  yield Valkyrie::AdapterContainer.new(persister: persist, query_service: metadata_adapter.query_service)
  buffer.persister.deletes.uniq(&:id).each do |delete|
    index_persister.delete(resource: delete)
  end
  index_persister.save_all(resources: buffer.query_service.find_all)
end

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(persister, buffer_class: Valkyrie::Persistence::DeleteTrackingBuffer) ⇒ BufferedPersister

Returns a new instance of BufferedPersister.



22
23
24
25
# File 'lib/valkyrie/persistence/buffered_persister.rb', line 22

def initialize(persister, buffer_class: Valkyrie::Persistence::DeleteTrackingBuffer)
  @persister = persister
  @buffer_class = buffer_class
end

Instance Attribute Details

#buffer_classObject (readonly)

Returns the value of attribute buffer_class.



20
21
22
# File 'lib/valkyrie/persistence/buffered_persister.rb', line 20

def buffer_class
  @buffer_class
end

#persisterObject (readonly)

Returns the value of attribute persister.



20
21
22
# File 'lib/valkyrie/persistence/buffered_persister.rb', line 20

def persister
  @persister
end

Instance Method Details

#delete(resource:) ⇒ Object



35
36
37
# File 'lib/valkyrie/persistence/buffered_persister.rb', line 35

def delete(resource:)
  persister.delete(resource: resource)
end

#save(resource:, external_resource: false) ⇒ Object



27
28
29
# File 'lib/valkyrie/persistence/buffered_persister.rb', line 27

def save(resource:, external_resource: false)
  persister.save(resource: resource, external_resource: external_resource)
end

#save_all(resources:) ⇒ Object



31
32
33
# File 'lib/valkyrie/persistence/buffered_persister.rb', line 31

def save_all(resources:)
  persister.save_all(resources: resources)
end

#with_buffer {|[Valkyrie::Persistence::CompositePersister.new(self, memory_buffer.persister), memory_buffer]| ... } ⇒ Object

Yields:



39
40
41
42
# File 'lib/valkyrie/persistence/buffered_persister.rb', line 39

def with_buffer
  memory_buffer = buffer_class.new
  yield [Valkyrie::Persistence::CompositePersister.new(self, memory_buffer.persister), memory_buffer]
end