Skip to content

Commit

Permalink
Add nil checks for manager_uuids and references
Browse files Browse the repository at this point in the history
Add nil checks for manager_uuids and references, nil references
lead to non existent elements, so we don't want them stored.
  • Loading branch information
Ladas committed Sep 26, 2017
1 parent a373229 commit 17c884a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/models/manager_refresh/inventory_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ def find_in_db(manager_uuid)
else
return db_data_index[manager_uuid] if db_data_index && db_data_index[manager_uuid]
# We haven't found the reference, lets add it to the list of references and load it
references << manager_uuid unless references.include?(manager_uuid) # O(1) since references is Set
references << manager_uuid if manager_uuid
end

# Put our existing data keys into loaded references
Expand Down Expand Up @@ -1081,6 +1081,7 @@ def extract_references(new_references = [])
hash_uuids_by_ref = []

new_references.each do |manager_uuid|
next if manager_uuid.nil?
uuids = manager_uuid.split(stringify_joiner)

reference = {}
Expand Down
12 changes: 8 additions & 4 deletions app/models/manager_refresh/inventory_collection/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def scan!

if targeted? && parent_inventory_collections.blank?
# We want to track what manager_uuids we should query from a db, for the targeted refresh
manager_uuids << inventory_object.manager_uuid
manager_uuid = inventory_object.manager_uuid
manager_uuids << manager_uuid if manager_uuid
end
end

Expand Down Expand Up @@ -116,14 +117,17 @@ def scan_inventory_object_attribute!(key, value)
# TODO(lsmola) solve the :key, since that requires data from the actual reference. At best our DB should be
# designed the way, we don't duplicate the data, but rather get them with a join. (3NF!)

value_inventory_collection.find_or_build(value.ems_ref)
value_inventory_collection.skeletal_manager_uuids << value.ems_ref
if value.ems_ref
value_inventory_collection.find_or_build(value.ems_ref)
value_inventory_collection.skeletal_manager_uuids << value.ems_ref
end
end
end

# Storing a reference in the target inventory_collection, then each IC knows about all the references and can
# e.g. load all the referenced uuids from a DB
value_inventory_collection.references << value.to_s
value_to_s = value.to_s
value_inventory_collection.references << value_to_s if value_to_s

if inventory_object_lazy?(value)
# Storing if attribute is a transitive dependency, so a lazy_find :key results in dependency
Expand Down

0 comments on commit 17c884a

Please sign in to comment.