Skip to content

Commit

Permalink
batch proxy document index adds into slices of 100 (DLC-1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Sep 11, 2024
1 parent f2f0b30 commit 4d1f060
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/dcv/solr/document_adapter/active_fedora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,19 @@ def proxies
end
end

def index_proxies(params = {softCommit: true})
def index_proxies(params = {softCommit: true}, conn = ::ActiveFedora::SolrService.instance.conn)
if has_struct_metadata?
conn = ::ActiveFedora::SolrService.instance.conn
# delete by query proxyIn_ssi: internal_uri
conn.delete_by_query("proxyIn_ssi:#{RSolr.solr_escape(obj.internal_uri())}")

# reindex proxies
proxy_docs = proxies.collect {|p| p.to_solr}
conn.add(proxy_docs, params: params)
proxy_docs
indexed_docs = []
proxies.each_slice(100) do |slice|
proxy_docs = slice.map(&:to_solr)
conn.add(proxy_docs, params: params)
indexed_docs.concat proxy_docs
end
indexed_docs
else
[]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,24 @@
end
end
describe '#proxies' do
it "produces proxy objects that respod to :to_solr from structMetadata" do
it "produces proxy objects that respond to :to_solr from structMetadata" do
expect(adapter.proxies.length).to be 7
expect(adapter.proxies.first).to respond_to(:to_solr)
end
end
describe '#index_proxies' do
let(:conn) { instance_double(RSolr::Client) }
before do
allow(conn).to receive(:add)
end
it "indexes proxy documents corresponding to structMetadata" do
expect(conn).to receive(:delete_by_query)
index_proxies = adapter.index_proxies({}, conn)
expect(index_proxies.length).to be 7
index_proxies.each do |proxy|
expect(proxy.keys).to include("id", "label_ssi", "proxyFor_ssi", "proxyIn_ssi", "type_ssim")
end
end
end
end
end

0 comments on commit 4d1f060

Please sign in to comment.