Skip to content

Commit

Permalink
Speed up dynamodb List() by only getting keys (#21159)
Browse files Browse the repository at this point in the history
* Speed up ddb list by only getting keys

* Add same optimization to has_children

* Add changeling

---------

Co-authored-by: Violet Hynes <[email protected]>
  • Loading branch information
thomashargrove and VioletHynes authored Jun 7, 2024
1 parent 8fd63b0 commit 2756303
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog/21159.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:improvement
storage/dynamodb: Speed up list and delete of large directories by only requesting keys from DynamoDB
```

10 changes: 10 additions & 0 deletions physical/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ func (d *DynamoDBBackend) List(ctx context.Context, prefix string) ([]string, er
}},
},
},
ProjectionExpression: aws.String("#key, #path"),
ExpressionAttributeNames: map[string]*string{
"#key": aws.String("Key"),
"#path": aws.String("Path"),
},
}

d.permitPool.Acquire()
Expand Down Expand Up @@ -453,6 +458,11 @@ func (d *DynamoDBBackend) hasChildren(prefix string, exclude []string) (bool, er
}},
},
},
ProjectionExpression: aws.String("#key, #path"),
ExpressionAttributeNames: map[string]*string{
"#key": aws.String("Key"),
"#path": aws.String("Path"),
},
// Avoid fetching too many items from DynamoDB for performance reasons.
// We want to know if there are any children we don't expect to see.
// Answering that question requires fetching a minimum of one more item
Expand Down

0 comments on commit 2756303

Please sign in to comment.