static async Task <(string itemIdText, Guid itemId, long size)[]> GetItemAndSizeListAsync(IAmazonDynamoDB client, string tableName, Guid ownerId, Guid scoreId) { var partitionKey = ScoreItemDatabaseUtils.ConvertToPartitionKey(ownerId); var score = ScoreDatabaseUtils.ConvertToBase64(scoreId); var request = new QueryRequest() { TableName = tableName, ExpressionAttributeNames = new Dictionary <string, string>() { ["#owner"] = ScoreItemDatabasePropertyNames.OwnerId, ["#item"] = ScoreItemDatabasePropertyNames.ItemId, }, ExpressionAttributeValues = new Dictionary <string, AttributeValue>() { [":owner"] = new AttributeValue(partitionKey), [":score"] = new AttributeValue(score), }, KeyConditionExpression = "#owner = :owner and begins_with(#item, :score)", }; try { var response = await client.QueryAsync(request); return(response.Items .Where(x => x[ScoreItemDatabasePropertyNames.ItemId].S != ScoreItemDatabaseConstant.ItemIdSummary) .Select(GetItemAndSizeAsync).ToArray()); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; }
static async Task <ScoreItemDatabaseItemDataBase[]> GetAsync(IAmazonDynamoDB client, string tableName, Guid ownerId) { var partitionKey = ScoreItemDatabaseUtils.ConvertToPartitionKey(ownerId); var request = new QueryRequest() { TableName = tableName, ExpressionAttributeNames = new Dictionary <string, string>() { ["#owner"] = ScoreItemDatabasePropertyNames.OwnerId, }, ExpressionAttributeValues = new Dictionary <string, AttributeValue>() { [":owner"] = new AttributeValue(partitionKey), }, KeyConditionExpression = "#owner = :owner", Limit = 500, }; try { var response = await client.QueryAsync(request); var items = response.Items.ToList(); while (0 < response.LastEvaluatedKey?.Count) { var nextRequest = new QueryRequest() { TableName = tableName, ExpressionAttributeNames = new Dictionary <string, string>() { ["#owner"] = ScoreItemDatabasePropertyNames.OwnerId, ["#item"] = ScoreItemDatabasePropertyNames.ItemId, }, ExpressionAttributeValues = new Dictionary <string, AttributeValue>() { [":owner"] = new AttributeValue(partitionKey), [":item"] = new AttributeValue(response .LastEvaluatedKey[ScoreItemDatabasePropertyNames.ItemId].S), }, KeyConditionExpression = "#owner = :owner and :item < #item", Limit = 500, }; var nextResponse = await client.QueryAsync(nextRequest); items.AddRange(nextResponse.Items); response = nextResponse; } return(items .Where(x => x[ScoreItemDatabasePropertyNames.ItemId].S != ScoreItemDatabaseConstant.ItemIdSummary) .Select(ScoreItemDatabaseUtils.ConvertFromDynamoDbValue) .ToArray()); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }