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

Minor inventory collection enhancements #15108

Merged
merged 2 commits into from
May 16, 2017
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
11 changes: 11 additions & 0 deletions app/models/manager_refresh/inventory_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ def data_collection_finalized?
data_collection_finalized
end

def supports_sti?
@supports_sti_cache ||= model_class.column_names.include?("type")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ladas this is the true/false/nil pattern, so you probably need something like the following so you are memoizing and not recalculating when value is false

def supports_sti?
  if @supports_sti_cache.nil?
    @supports_sti_cache = model_class.column_names.include?("type")
  end
  @supports_sti_cache
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, nice catch, you are right of course :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

def <<(inventory_object)
unless data_index[inventory_object.manager_uuid]
data_index[inventory_object.manager_uuid] = inventory_object
Expand Down Expand Up @@ -476,6 +480,13 @@ def new_inventory_object(hash)
def build(hash)
hash = hash.merge(builder_params)
inventory_object = new_inventory_object(hash)

uuid = inventory_object.manager_uuid
# Each InventoryObject must be able to build an UUID, return nil if it can't
return nil if uuid.blank?
# Return existing InventoryObject if we have it
return data_index[uuid] if data_index[uuid]
# Store new InventoryObject and return it
push(inventory_object)
inventory_object
end
Expand Down