Skip to content

Commit

Permalink
Refactor AWS plugin and don't send excessive Exist: true attribute …
Browse files Browse the repository at this point in the history
…to ensure an item with specified partition key exists
  • Loading branch information
andrykonchin committed May 27, 2023
1 parent 18d47a4 commit 464f115
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
5 changes: 1 addition & 4 deletions lib/dynamoid/adapter_plugin/aws_sdk_v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,7 @@ def expected_stanza(conditions = nil)
conditions.delete(:unless_exists).try(:each) do |col|
expected[col.to_s][:exists] = false
end
conditions.delete(:if_exists).try(:each) do |col, val|
expected[col.to_s][:exists] = true
expected[col.to_s][:value] = val
end

conditions.delete(:if).try(:each) do |col, val|
expected[col.to_s][:value] = val
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dynamoid/persistence/save.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def options_to_update_item
end

conditions = {}
conditions[:if_exists] ||= {}
conditions[:if_exists][@model.class.hash_key] = @model.hash_key
conditions[:if] ||= {}
conditions[:if][@model.class.hash_key] = @model.hash_key

# Add an optimistic locking check if the lock_version column exists
if @model.class.attributes[:lock_version]
Expand Down
4 changes: 2 additions & 2 deletions lib/dynamoid/persistence/update_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def options_to_update_item
end

conditions = @conditions.deep_dup
conditions[:if_exists] ||= {}
conditions[:if_exists][@model_class.hash_key] = @partition_key
conditions[:if] ||= {}
conditions[:if][@model_class.hash_key] = @partition_key
options[:conditions] = conditions

options
Expand Down

0 comments on commit 464f115

Please sign in to comment.