Browse Source

Keep the logs in memory (#1955)

pull/1961/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
2ab79b2f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/services/exports/lettings_log_export_service.rb
  2. 38
      spec/services/exports/lettings_log_export_service_spec.rb

4
app/services/exports/lettings_log_export_service.rb

@ -90,11 +90,11 @@ module Exports
retrieve_lettings_logs(start_time, recent_export, full_update).filter_by_year(collection) retrieve_lettings_logs(start_time, recent_export, full_update).filter_by_year(collection)
.where("created_at > ?", last_processed_marker) .where("created_at > ?", last_processed_marker)
.order(:created_at) .order(:created_at)
.limit(MAX_XML_RECORDS) .limit(MAX_XML_RECORDS).to_a
else else
retrieve_lettings_logs(start_time, recent_export, full_update).filter_by_year(collection) retrieve_lettings_logs(start_time, recent_export, full_update).filter_by_year(collection)
.order(:created_at) .order(:created_at)
.limit(MAX_XML_RECORDS) .limit(MAX_XML_RECORDS).to_a
end end
break if lettings_logs_slice.empty? break if lettings_logs_slice.empty?

38
spec/services/exports/lettings_log_export_service_spec.rb

@ -292,6 +292,44 @@ RSpec.describe Exports::LettingsLogExportService do
end end
end end
context "and underlying data changes between getting the logs and writting the manifest" do
before do
FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 2, 1))
FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 4, 1))
end
def remove_logs(logs)
logs.each(&:destroy)
file = Tempfile.new
doc = Nokogiri::XML("<forms/>")
doc.write_xml_to(file, encoding: "UTF-8")
file.rewind
file
end
def create_fake_maifest
file = Tempfile.new
doc = Nokogiri::XML("<forms/>")
doc.write_xml_to(file, encoding: "UTF-8")
file.rewind
file
end
it "maintains the same record number" do
# rubocop:disable RSpec/SubjectStub
allow(export_service).to receive(:build_export_xml) do |logs|
remove_logs(logs)
end
allow(export_service).to receive(:build_manifest_xml) do
create_fake_maifest
end
expect(export_service).to receive(:build_manifest_xml).with(1)
# rubocop:enable RSpec/SubjectStub
export_service.export_xml_lettings_logs
end
end
context "when this is a second export (partial)" do context "when this is a second export (partial)" do
before do before do
start_time = Time.zone.local(2022, 6, 1) start_time = Time.zone.local(2022, 6, 1)

Loading…
Cancel
Save