Skip to content

Commit

Permalink
Merge pull request #387 from ivplus/386-extract-marc-deletes
Browse files Browse the repository at this point in the history
Don't try to parse delete files as marc records
  • Loading branch information
corylown authored Oct 25, 2021
2 parents eb835eb + 8afa406 commit 1c13382
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/jobs/generate_delta_dump_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def perform(organization)
hash = current_marc_records(uploads)

uploads.each do |upload|
upload.each_marc_record_metadata.each do |record|
upload.each_marc_record_metadata(checksum: false).each do |record|
next unless hash.dig(record.marc001, 'file_id') == record.file_id

if hash.dig(record.marc001, 'status') == 'delete'
Expand Down Expand Up @@ -57,7 +57,7 @@ def current_marc_records(uploads)
hash = {}

uploads.each do |upload|
upload.each_marc_record_metadata.each do |record|
upload.each_marc_record_metadata(checksum: false).each do |record|
hash[record.marc001] = record.attributes.slice('file_id', 'status')
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/generate_full_dump_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def perform(organization)
hash = current_marc_records(organization.default_stream.uploads)

organization.default_stream.uploads.each do |upload|
upload.each_marc_record_metadata.each do |record|
upload.each_marc_record_metadata(checksum: false).each do |record|
next unless hash.dig(record.marc001, 'file_id') == record.file_id || hash.dig(record.marc001, 'status') == 'delete'

writer.write_marc_record(record)
Expand Down Expand Up @@ -68,7 +68,7 @@ def current_marc_records(uploads)
hash = {}

uploads.each do |upload|
upload.each_marc_record_metadata.each do |record|
upload.each_marc_record_metadata(checksum: false).each do |record|
hash[record.marc001] = record.attributes.slice('file_id', 'status')
end
end
Expand Down
23 changes: 13 additions & 10 deletions app/models/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ def archive
files.find_each(&:purge_later)
end

def each_marc_record_metadata(&block)
return to_enum(:each_marc_record_metadata) unless block
def each_marc_record_metadata(**options, &block)
return to_enum(:each_marc_record_metadata, **options) unless block

files.each do |file|
service = MarcRecordService.new(file.blob)

format = service.identify

extract_marc_record_delete_metadata(file, &block) if format == :delete

next if format == :unknown

extract_marc_record_metadata(file, service, &block)
case format
when :delete
extract_marc_record_delete_metadata(file, &block)
when :unknown
next
else
extract_marc_record_metadata(file, service, **options, &block)
end
rescue StandardError => e
Honeybadger.notify(e)
end
Expand Down Expand Up @@ -88,8 +91,8 @@ def extract_marc_record_delete_metadata(file)
end
end

def extract_marc_record_metadata(file, service)
return to_enum(:extract_marc_record_metadata, file, service) unless block_given?
def extract_marc_record_metadata(file, service, checksum: true)
return to_enum(:extract_marc_record_metadata, file, service, checksum: checksum) unless block_given?

service.each_with_metadata do |record, metadata|
out = MarcRecord.new(
Expand All @@ -101,7 +104,7 @@ def extract_marc_record_metadata(file, service)
json: Zlib::Deflate.new.deflate(record.to_marchash.to_json, Zlib::FINISH)
)

out.checksum ||= Digest::MD5.hexdigest(record.to_xml.to_s)
out.checksum ||= Digest::MD5.hexdigest(record.to_xml.to_s) if checksum

yield out
end
Expand Down

0 comments on commit 1c13382

Please sign in to comment.