From 2e976d10811e3f17e21f1c26dc5d343c52723288 Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Tue, 20 Mar 2018 19:20:27 +0100 Subject: [PATCH] Fix DB loading strategy Fix DB loading strategy. This was fixed in master, by refactoring the DB loading indexes. We need this change for backported Azure refresh. What this allows is using both find and lazy_find on InventoryCollection and have all references loaded correctly from the DB. Right now, only the find was loaded and the lazy_find edges were not loaded. Partially fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1558078 --- app/models/manager_refresh/inventory_collection.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/manager_refresh/inventory_collection.rb b/app/models/manager_refresh/inventory_collection.rb index af4a62fb600..8c5f320e966 100644 --- a/app/models/manager_refresh/inventory_collection.rb +++ b/app/models/manager_refresh/inventory_collection.rb @@ -454,6 +454,7 @@ def initialize(model_class: nil, manager_ref: nil, association: nil, parent: nil @loaded_references = Set.new @db_data_index = nil @data_collection_finalized = false + @all_references_loaded = false @created_records = [] @updated_records = [] @@ -980,6 +981,7 @@ def full_collection_for_comparison private + attr_accessor :all_references_loaded attr_writer :attributes_blacklist, :attributes_whitelist, :db_data_index # Returns array of records identities @@ -1004,7 +1006,7 @@ def record_identity(record) # @param manager_uuid [String] a manager_uuid of the InventoryObject we search in the local DB def find_in_db(manager_uuid) # Use the cached db_data_index only data_collection_finalized?, meaning no new reference can occur - if data_collection_finalized? && db_data_index + if data_collection_finalized? && db_data_index && all_references_loaded return db_data_index[manager_uuid] else return db_data_index[manager_uuid] if db_data_index && db_data_index[manager_uuid] @@ -1017,6 +1019,8 @@ def find_in_db(manager_uuid) # Load the rest of the references from the DB populate_db_data_index! + self.all_references_loaded = true if data_collection_finalized? + db_data_index[manager_uuid] end