samvera-nesting_indexer 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75345930203b00001250fed039cf25d5fb6924a0
4
- data.tar.gz: 976fdb5ce55d267d2d579512c58fdcec074da652
3
+ metadata.gz: 3933e26eda523a5609b140bccf34d4c291669292
4
+ data.tar.gz: d6d13b4ba28d3863aaaf32f40a8524de8f37ab5b
5
5
  SHA512:
6
- metadata.gz: 1a39a7a17bf963fa3b0e0f63779bbad6591331b1ad1da88b8f66e471b7bf7e821e57a82b21cf86ee76b50d192fd0fbf4727e41cadfcb1946cdeb81d32bcfb826
7
- data.tar.gz: b15f80f10ece6a9cb33bf3ee6349fb00548ee2ba721dafbb75ed37393ac0db700ced920f2acd850aae60683b5eafe19202d647ce8935cc7225db865689287334
6
+ metadata.gz: fbd5fa597ab1afc270d34a8e501e39a9aa6d066f3442b87aa7f692c9bbbd8d719dcd6c08cd196e0b95a17dc13918588b33fad42b8f86e4cb65d0e25d31297f8b
7
+ data.tar.gz: 164221f096a42d550d624f6658fbc0e3127560935f05684f573c53de5c7772b4b68665a5058788a32fda61c06fbaf41936da0ea3bb32505f0cc874b7a9b1b3ec
@@ -7,27 +7,37 @@ module Samvera
7
7
  module AbstractAdapter
8
8
  # @api public
9
9
  # @param id [String]
10
- # @return Samvera::NestingIndexer::Document::PreservationDocument
10
+ # @return [Samvera::NestingIndexer::Document::PreservationDocument]
11
11
  def self.find_preservation_document_by(id:)
12
12
  raise NotImplementedError
13
13
  end
14
14
 
15
15
  # @api public
16
16
  # @param id [String]
17
- # @return Samvera::NestingIndexer::Documents::IndexDocument
17
+ # @return [Samvera::NestingIndexer::Documents::IndexDocument]
18
18
  def self.find_index_document_by(id:)
19
19
  raise NotImplementedError
20
20
  end
21
21
 
22
22
  # @api public
23
- # @yield Samvera::NestingIndexer::Document::PreservationDocument
24
- def self.each_preservation_document(&block)
23
+ # @since 0.7.0
24
+ # @yieldparam id [String] The `id` of the preservation document
25
+ # @yieldparam parent_ids [String] The ids of the parent objects of this presevation document
26
+ def self.each_perservation_document_id_and_parent_ids(&block)
27
+ raise NotImplementedError
28
+ end
29
+
30
+ # @api public
31
+ # @since 0.7.0
32
+ # @param id [String] The `id` of the preservation document
33
+ # @return [Array<String>] The parent ids of the given preservation document
34
+ def self.find_preservation_parent_ids_for(id:)
25
35
  raise NotImplementedError
26
36
  end
27
37
 
28
38
  # @api public
29
39
  # @param document [Samvera::NestingIndexer::Documents::IndexDocument]
30
- # @yield Samvera::NestingIndexer::Documents::IndexDocument
40
+ # @yield [Samvera::NestingIndexer::Documents::IndexDocument]
31
41
  def self.each_child_document_of(document:, &block)
32
42
  raise NotImplementedError
33
43
  end
@@ -19,20 +19,27 @@ module Samvera
19
19
 
20
20
  # @api public
21
21
  # @param id [String]
22
- # @return Samvera::NestingIndexer::Documents::IndexDocument
22
+ # @return [Samvera::NestingIndexer::Documents::IndexDocument]
23
23
  def self.find_index_document_by(id:)
24
24
  Index.find(id)
25
25
  end
26
26
 
27
27
  # @api public
28
- # @yield Samvera::NestingIndexer::Document::PreservationDocument
29
- def self.each_preservation_document(&block)
30
- Preservation.find_each { |document| block.call(document) }
28
+ # @yieldparam id [String] The `id` of the preservation document
29
+ # @yieldparam parent_ids [String] The ids of the parent objects of this presevation document
30
+ def self.each_perservation_document_id_and_parent_ids(&block)
31
+ Preservation.find_each do |document|
32
+ block.call(document.id, document.parent_ids)
33
+ end
34
+ end
35
+
36
+ def self.find_preservation_parent_ids_for(id:)
37
+ Preservation.find(id).parent_ids
31
38
  end
32
39
 
33
40
  # @api public
34
41
  # @param document [Samvera::NestingIndexer::Documents::IndexDocument]
35
- # @yield Samvera::NestingIndexer::Documents::IndexDocument
42
+ # @yield [Samvera::NestingIndexer::Documents::IndexDocument]
36
43
  def self.each_child_document_of(document:, &block)
37
44
  Index.each_child_document_of(document: document, &block)
38
45
  end
@@ -41,7 +48,7 @@ module Samvera
41
48
  # This is not something that I envision using in the production environment;
42
49
  # It is hear to keep the Preservation system isolated and accessible only through interfaces.
43
50
  # @param attributes [Hash]
44
- # @return Samvera::NestingIndexer::Documents::PreservationDocument
51
+ # @return [Samvera::NestingIndexer::Documents::PreservationDocument]
45
52
  def self.write_document_attributes_to_preservation_layer(attributes)
46
53
  Preservation.write_document(attributes)
47
54
  end
@@ -52,7 +59,7 @@ module Samvera
52
59
  # @param parent_ids [Array<String>]
53
60
  # @param ancestors [Array<String>]
54
61
  # @param pathnames [Array<String>]
55
- # @return Hash - the attributes written to the indexing layer
62
+ # @return [Hash] - the attributes written to the indexing layer
56
63
  def self.write_document_attributes_to_index_layer(id:, parent_ids:, ancestors:, pathnames:)
57
64
  Index.write_document(id: id, parent_ids: parent_ids, ancestors: ancestors, pathnames: pathnames)
58
65
  end
@@ -19,6 +19,21 @@ if defined?(RSpec)
19
19
  expect(block_parameter_extracter.call(subject)).to be_empty
20
20
  end
21
21
  end
22
+ describe '.find_preservation_parent_ids_for' do
23
+ subject { described_class.method(:find_preservation_parent_ids_for) }
24
+
25
+ it 'requires the :id keyword (and does not require any others)' do
26
+ expect(required_keyword_parameters.call(subject)).to eq([:id])
27
+ end
28
+
29
+ it 'does not require any other parameters (besides :id)' do
30
+ expect(required_parameters.call(subject)).to eq(required_keyword_parameters.call(subject))
31
+ end
32
+
33
+ it 'does not expect a block' do
34
+ expect(block_parameter_extracter.call(subject)).to be_empty
35
+ end
36
+ end
22
37
  describe '.find_index_document_by' do
23
38
  subject { described_class.method(:find_index_document_by) }
24
39
 
@@ -34,8 +49,8 @@ if defined?(RSpec)
34
49
  expect(block_parameter_extracter.call(subject)).to be_empty
35
50
  end
36
51
  end
37
- describe '.each_preservation_document' do
38
- subject { described_class.method(:each_preservation_document) }
52
+ describe '.each_perservation_document_id_and_parent_ids' do
53
+ subject { described_class.method(:each_perservation_document_id_and_parent_ids) }
39
54
 
40
55
  it 'requires no keywords' do
41
56
  expect(required_keyword_parameters.call(subject)).to eq([])
@@ -21,7 +21,7 @@ module Samvera
21
21
  # @param maximum_nesting_depth [Integer] detect cycles in the graph
22
22
  # @param adapter [Samvera::NestingIndexer::Adapters::AbstractAdapter] Conforms to the Samvera::NestingIndexer::Adapters::AbstractAdapter interface
23
23
  def initialize(maximum_nesting_depth:, id_reindexer:, adapter:)
24
- @max_maximum_nesting_depth = maximum_nesting_depth.to_i
24
+ @maximum_nesting_depth = maximum_nesting_depth.to_i
25
25
  @id_reindexer = id_reindexer
26
26
  @adapter = adapter
27
27
  @processed_ids = []
@@ -29,12 +29,14 @@ module Samvera
29
29
 
30
30
  # @todo Would it make sense to leverage an each_preservation_id instead?
31
31
  def call
32
- @adapter.each_preservation_document { |document| recursive_reindex(document, max_maximum_nesting_depth) }
32
+ @adapter.each_perservation_document_id_and_parent_ids do |id, parent_ids|
33
+ recursive_reindex(id: id, parent_ids: parent_ids, time_to_live: maximum_nesting_depth)
34
+ end
33
35
  end
34
36
 
35
37
  private
36
38
 
37
- attr_reader :max_maximum_nesting_depth, :processed_ids, :id_reindexer
39
+ attr_reader :maximum_nesting_depth, :processed_ids, :id_reindexer
38
40
 
39
41
  # When we find a document, reindex it if it doesn't have a parent. If it has a parent, reindex the parent first.
40
42
  #
@@ -43,17 +45,17 @@ module Samvera
43
45
  #
44
46
  # The reindexing process assumes that an object's parents have been indexed; Thus we need to
45
47
  # walk up the parent graph to reindex the parents before we start on the child.
46
- def recursive_reindex(document, maximum_nesting_depth = max_maximum_nesting_depth)
47
- return true if processed_ids.include?(document.id)
48
- raise Exceptions::CycleDetectionError, document.id if maximum_nesting_depth <= 0
49
- document.parent_ids.each do |parent_id|
50
- parent_document = @adapter.find_preservation_document_by(id: parent_id)
51
- recursive_reindex(parent_document, maximum_nesting_depth - 1)
48
+ def recursive_reindex(id:, parent_ids:, time_to_live:)
49
+ return true if processed_ids.include?(id)
50
+ raise Exceptions::CycleDetectionError, id if time_to_live <= 0
51
+ parent_ids.each do |parent_id|
52
+ grand_parent_ids = @adapter.find_preservation_parent_ids_for(id: parent_id)
53
+ recursive_reindex(id: parent_id, parent_ids: grand_parent_ids, time_to_live: maximum_nesting_depth - 1)
52
54
  end
53
- reindex_a_id(document.id)
55
+ reindex_an_id(id)
54
56
  end
55
57
 
56
- def reindex_a_id(id)
58
+ def reindex_an_id(id)
57
59
  id_reindexer.call(id: id)
58
60
  processed_ids << id
59
61
  rescue StandardError => e
@@ -1,5 +1,5 @@
1
1
  module Samvera
2
2
  module NestingIndexer
3
- VERSION = "0.6.0".freeze
3
+ VERSION = "0.7.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samvera-nesting_indexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen