Skip to content

Commit

Permalink
Use supports_timestamps_max for conditionalization of the entire path
Browse files Browse the repository at this point in the history
Use supports_timestamps_max for conditionalization of the entire path
  • Loading branch information
Ladas committed Aug 27, 2018
1 parent 3ad9192 commit 6792e79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/models/manager_refresh/save_collection/saver/base.rb
Expand Up @@ -407,8 +407,8 @@ def supports_remote_data_timestamp?(all_attribute_keys)
end

# @return [Boolean] true if the model_class has remote_data_timestamp column
def supports_max_timestamp?
@supports_max_timestamp_cache ||= model_class.column_names.include?("timestamps_max")
def supports_timestamps_max?
@supports_timestamps_max_cache ||= model_class.column_names.include?("timestamps_max")
end
end
end
Expand Down
Expand Up @@ -287,19 +287,22 @@ def create_or_update_partial_records(all_attribute_keys)
base_columns = unique_index_columns + internal_columns + [:timestamps_max]
columns_for_per_column_batches = all_attribute_keys - base_columns

# TODO(lsmola) needs to have supports timestamp or resource version
all_attribute_keys << :timestamps
all_attribute_keys << :timestamps_max
if supports_timestamps_max?
all_attribute_keys << :timestamps
all_attribute_keys << :timestamps_max
end

indexed_inventory_objects = {}
hashes = []
create_time = time_now

skeletal_inventory_objects_index.each do |index, inventory_object|
hash = skeletal_attributes_index.delete(index)
# Partial create or update nevers sets a timestamp for the whole row
hash[:timestamps_max] = hash.delete(:timestamp)
hash[:timestamps] = columns_for_per_column_batches.map { |x| [x, hash[:timestamps_max]] if hash.key?(x) }.compact.to_h
# Partial create or update must never set a timestamp for the whole row
if supports_timestamps_max?
hash[:timestamps_max] = hash.delete(:timestamp)
hash[:timestamps] = columns_for_per_column_batches.map { |x| [x, hash[:timestamps_max]] if hash.key?(x) }.compact.to_h
end
# Transform hash to DB format
hash = transform_to_hash!(all_attribute_keys, hash)

Expand Down
Expand Up @@ -93,7 +93,7 @@ def build_insert_query(all_attribute_keys, hashes, on_conflict: nil, mode:, colu
insert_query += %{
SET #{(all_attribute_keys_array - ignore_cols).map { |key| build_insert_set_cols(key) }.join(", ")}
}
if supports_max_timestamp?
if supports_timestamps_max?
# TODO(lsmola) we should have EXCLUDED.timestamp > #{table_name}.timestamp, but if skeletal precreate
# creates the row, it sets timestamp. Should we combine it with complete => true only? We probably need
# to set the timestamp, otherwise we can't touch it in the update clause. Maybe we coud set it as
Expand Down

0 comments on commit 6792e79

Please sign in to comment.