Skip to content

Commit

Permalink
Merge pull request ManageIQ#17724 from Ladas/fix_refresh_time_and_mem…
Browse files Browse the repository at this point in the history
…ory_issues

Fix refresh time and memory issues
  • Loading branch information
agrare committed Jul 18, 2018
2 parents cd3ac20 + b893632 commit 446b554
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/models/manager_refresh/inventory_collection/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def scan_inventory_object_attribute!(key, value)

# 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.add_reference(value.reference, :key => value.try(:key))
value_inventory_collection.add_reference(value.reference, :key => value.key)

if inventory_object_lazy?(value)
# Storing if attribute is a transitive dependency, so a lazy_find :key results in dependency
Expand Down
50 changes: 4 additions & 46 deletions app/models/manager_refresh/inventory_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def load
self
end

def key
nil
end

# Transforms InventoryObject object data into hash format with keys that are column names and resolves correct
# values of the foreign keys (even the polymorphic ones)
#
Expand Down Expand Up @@ -176,52 +180,6 @@ def self.add_attributes(inventory_object_attributes)

private

# @return [Set] all model's writer names
def allowed_writers
return [] unless model_class

# Get all writers of a model
@allowed_writers ||= (model_class.new.methods - Object.methods).grep(/^[\w]+?\=$/).to_set
end

# @return [Set] all model's reader names
def allowed_readers
return [] unless model_class

# Get all readers inferred from writers of a model
@allowed_readers ||= allowed_writers.map { |x| x.to_s.delete("=").to_sym }.to_set
end

def method_missing(method_name, *arguments, &block)
if allowed_writers.include?(method_name)
self.class.define_data_writer(method_name)
public_send(method_name, arguments[0])
elsif allowed_readers.include?(method_name)
self.class.define_data_reader(method_name)
public_send(method_name)
else
super
end
end

def respond_to_missing?(method_name, _include_private = false)
allowed_writers.include?(method_name) || allowed_readers.include?(method_name) || super
end

def self.define_data_writer(data_key)
define_method(data_key) do |value|
public_send(:[]=, data_key.to_s.delete("=").to_sym, value)
end
end
private_class_method :define_data_writer

def self.define_data_reader(data_key)
define_method(data_key) do
public_send(:[], data_key)
end
end
private_class_method :define_data_reader

# Return true passed key representing a getter is an association
#
# @param inventory_collection_scope [ManagerRefresh::InventoryCollection]
Expand Down

0 comments on commit 446b554

Please sign in to comment.