Don't request data from DynamoDB if we already have it locally.

This commit is contained in:
Jon Chambers 2021-02-04 17:39:48 -05:00 committed by Jon Chambers
parent e1f4deaacc
commit a015237fd2
1 changed files with 8 additions and 6 deletions

View File

@ -138,10 +138,10 @@ public class KeysDynamoDb extends AbstractDynamoDbStore implements PreKeyStore {
final QuerySpec querySpec = new QuerySpec().withKeyConditionExpression("#uuid = :uuid") final QuerySpec querySpec = new QuerySpec().withKeyConditionExpression("#uuid = :uuid")
.withNameMap(Map.of("#uuid", KEY_ACCOUNT_UUID)) .withNameMap(Map.of("#uuid", KEY_ACCOUNT_UUID))
.withValueMap(Map.of(":uuid", getPartitionKey(account.getUuid()))) .withValueMap(Map.of(":uuid", getPartitionKey(account.getUuid())))
.withProjectionExpression(KEY_ACCOUNT_UUID + ", " + KEY_DEVICE_ID_KEY_ID) .withProjectionExpression(KEY_DEVICE_ID_KEY_ID)
.withConsistentRead(true); .withConsistentRead(true);
deleteItemsMatchingQuery(querySpec); deleteItemsForAccountMatchingQuery(account, querySpec);
}); });
} }
@ -152,19 +152,21 @@ public class KeysDynamoDb extends AbstractDynamoDbStore implements PreKeyStore {
.withNameMap(Map.of("#uuid", KEY_ACCOUNT_UUID, "#sort", KEY_DEVICE_ID_KEY_ID)) .withNameMap(Map.of("#uuid", KEY_ACCOUNT_UUID, "#sort", KEY_DEVICE_ID_KEY_ID))
.withValueMap(Map.of(":uuid", getPartitionKey(account.getUuid()), .withValueMap(Map.of(":uuid", getPartitionKey(account.getUuid()),
":sortprefix", getSortKeyPrefix(deviceId))) ":sortprefix", getSortKeyPrefix(deviceId)))
.withProjectionExpression(KEY_ACCOUNT_UUID + ", " + KEY_DEVICE_ID_KEY_ID) .withProjectionExpression(KEY_DEVICE_ID_KEY_ID)
.withConsistentRead(true); .withConsistentRead(true);
deleteItemsMatchingQuery(querySpec); deleteItemsForAccountMatchingQuery(account, querySpec);
}); });
} }
private void deleteItemsMatchingQuery(final QuerySpec querySpec) { private void deleteItemsForAccountMatchingQuery(final Account account, final QuerySpec querySpec) {
final byte[] partitionKey = getPartitionKey(account.getUuid());
writeInBatches(table.query(querySpec), batch -> { writeInBatches(table.query(querySpec), batch -> {
final TableWriteItems writeItems = new TableWriteItems(table.getTableName()); final TableWriteItems writeItems = new TableWriteItems(table.getTableName());
for (final Item item : batch) { for (final Item item : batch) {
writeItems.addPrimaryKeyToDelete(new PrimaryKey(KEY_ACCOUNT_UUID, item.getBinary(KEY_ACCOUNT_UUID), KEY_DEVICE_ID_KEY_ID, item.getBinary(KEY_DEVICE_ID_KEY_ID))); writeItems.addPrimaryKeyToDelete(new PrimaryKey(KEY_ACCOUNT_UUID, partitionKey, KEY_DEVICE_ID_KEY_ID, item.getBinary(KEY_DEVICE_ID_KEY_ID)));
} }
executeTableWriteItemsUntilComplete(writeItems); executeTableWriteItemsUntilComplete(writeItems);