Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gaprindashvili] Fix DB loading strategy #17176

Merged
merged 1 commit into from
Mar 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/models/manager_refresh/inventory_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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

Expand Down