From 2ab79b2f3e2ffbd3b3a8be5fbce3943e787be00c Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Thu, 5 Oct 2023 10:20:29 +0100
Subject: [PATCH] Keep the logs in memory (#1955)
---
.../exports/lettings_log_export_service.rb | 4 +-
.../lettings_log_export_service_spec.rb | 38 +++++++++++++++++++
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/app/services/exports/lettings_log_export_service.rb b/app/services/exports/lettings_log_export_service.rb
index 16ce5c187..8fafe28e9 100644
--- a/app/services/exports/lettings_log_export_service.rb
+++ b/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)
.where("created_at > ?", last_processed_marker)
.order(:created_at)
- .limit(MAX_XML_RECORDS)
+ .limit(MAX_XML_RECORDS).to_a
else
retrieve_lettings_logs(start_time, recent_export, full_update).filter_by_year(collection)
.order(:created_at)
- .limit(MAX_XML_RECORDS)
+ .limit(MAX_XML_RECORDS).to_a
end
break if lettings_logs_slice.empty?
diff --git a/spec/services/exports/lettings_log_export_service_spec.rb b/spec/services/exports/lettings_log_export_service_spec.rb
index 5402c19db..3913547e8 100644
--- a/spec/services/exports/lettings_log_export_service_spec.rb
+++ b/spec/services/exports/lettings_log_export_service_spec.rb
@@ -292,6 +292,44 @@ RSpec.describe Exports::LettingsLogExportService do
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("")
+ doc.write_xml_to(file, encoding: "UTF-8")
+ file.rewind
+ file
+ end
+
+ def create_fake_maifest
+ file = Tempfile.new
+ doc = Nokogiri::XML("")
+ 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
before do
start_time = Time.zone.local(2022, 6, 1)