dynamodb-toolbox
dynamodb-toolbox copied to clipboard
Improvement: Redundant ExpressionAttribute/Values
We noticed that this library doesn't deduplicate ExpressionAttributeNames or ExpressionAttributeValues
Example request
{
"TableName": "...............",
"Key": {
"id": {
"S": "ecf9e8ee-8518-4b7c-b3c0-4e308e9bbeaa"
}
},
"UpdateExpression": "SET #slug = :slug, #inputString = :inputString, #target = :target, #type = :type, #timestamp = :timestamp",
"ExpressionAttributeNames": {
"#slug": "slug",
"#inputString": "inputString",
"#target": "target",
"#type": "type",
"#timestamp": "timestamp",
"#attr1": "target",
"#attr2": "target"
},
"ExpressionAttributeValues": {
":slug": {
"S": "50-percent-off"
},
":inputString": {
"S": "50% off"
},
":target": {
"S": "620fa000-e1d8-4da0-9407-42814024cedb"
},
":type": {
"S": "offer"
},
":timestamp": {
"S": "2018-12-21T21:11:19.000Z"
},
":attr2": {
"S": "620fa000-e1d8-4da0-9407-42814024cedb"
}
},
"ConditionExpression": "attribute_not_exists(#attr1) OR #attr2 = :attr2",
"ReturnValues": "ALL_OLD"
}
You can see that target exists twice. In this case, since there is not a lot of data, this is ok.
Is this something that this library should handle?
Thanks for pointing this out, @simlu. I'm not sure this would be much of an optimization, but I will add it as an enhancement to consider.