Skip to content

Commit

Permalink
WIP compare decimal quota_* columns correctly in batch saver
Browse files Browse the repository at this point in the history
  • Loading branch information
cben committed Feb 12, 2018
1 parent 1d35a7d commit 202a880
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/models/ems_refresh/save_inventory_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def fetch(hash)

# Coerce each hash value into the db column type for valid lookup during fetch_path
coerced_hash_values = hash_values.zip(key_attribute_types).collect do |value, type|
raise "BOO" if value.hash != type.cast(value).hash
type.cast(value)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def save!(association)
all_attribute_keys = Set.new + inventory_collection.batch_extra_attributes

inventory_collection.each do |inventory_object|
# TODO(cben): quota columns cast?
attributes = inventory_object.attributes_with_keys(inventory_collection, all_attribute_keys)
index = build_stringified_reference(attributes, unique_index_keys)

Expand Down Expand Up @@ -100,15 +101,22 @@ def update_or_destroy_records!(records_batch_iterator, inventory_objects_index,

next unless assert_distinct_relation(primary_key_value)

# Incoming values are in SQL string form.
# TODO(lsmola) unify this behavior with object_index_with_keys method in InventoryCollection
# TODO(lsmola) maybe we can drop the whole pure sql fetching, since everything will be targeted refresh
# with streaming refresh? Maybe just metrics and events will not be, but those should be upsert only
index = unique_index_keys_to_s.map do |attribute|
value = record_key(record, attribute)
if attribute == "timestamp"
type = model_class.type_for_attribute(attribute)
type.cast(record_key(record, attribute)).utc.iso8601.to_s
type.cast(value).utc.iso8601.to_s
elsif %w(quota_desired quota_enforced quota_observed).include?(attribute)
# Postgres formats decimal columns with fixed number of digits e.g. '0.100'.
# Need to parse and let Ruby format the value to have a comparable string.
type = model_class.type_for_attribute(attribute)
type.cast(value).to_s
else
record_key(record, attribute).to_s
value.to_s
end
end.join("__")

Expand Down

0 comments on commit 202a880

Please sign in to comment.