Skip to content

Commit

Permalink
Check timestamp before updating
Browse files Browse the repository at this point in the history
Check timestamp before updating, to avoid extra query
  • Loading branch information
Ladas committed Aug 27, 2018
1 parent dfdd349 commit 810adeb
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ def update_or_destroy_records!(records_batch_iterator, inventory_objects_index,
next unless assert_referential_integrity(hash)
inventory_object.id = primary_key_value

if inventory_collection.parallel_safe? && supports_remote_data_timestamp?(all_attribute_keys)
record_timestamp = record.try(:timestamp) || record.try(:[], :timestamp)
record_timestamps_max = record.try(:timestamps_max) || record.try(:[], :timestamps_max)
hash_timestamp = hash[:timestamp]

# Skip updating this record, because it is old
next if record_timestamp && hash_timestamp && record_timestamp >= hash_timestamp

# Some column has bigger timestamp than the whole row, we need to store the row partially
if record_timestamps_max && hash_timestamp && record_timestamps_max > hash_timestamp
inventory_collection.skeletal_primary_index.skeletonize_primary_index(inventory_object.manager_uuid)
next
end
end

hash_for_update = if inventory_collection.use_ar_object?
record.assign_attributes(hash.except(:id, :type))
values_for_database!(all_attribute_keys,
Expand Down

0 comments on commit 810adeb

Please sign in to comment.