Using .net core api (c#) with dynamodb here. I have my dbmanager class as:
public class DbManager<T> : DynamoDBContext, IDynamoDbManager<T> where T : class
{
private DynamoDBOperationConfig _config;
public DbManager(IAmazonDynamoDB client, string tableName) : base(client)
{
_config = new DynamoDBOperationConfig()
{
OverrideTableName = tableName
};
}
public Task<List<T>> GetAsync(IEnumerable<ScanCondition> conditions)
{
return ScanAsync<T>(conditions, _config).GetRemainingAsync();
}
}
public interface IDbManager<T> : IDisposable where T : class
{
Task<List<T>> GetAsync(IEnumerable<ScanCondition> conditions);
}
And in my controller:
public class ValuesController : Controller
{
private readonly IDbManager<MyData> _dbManager;
public ValuesController(IDbManager<MyData> dbManager)
{
_dbManager = dbManager;
}
[HttpGet()]
[Route("sets/filter")]
public async Task<IActionResult> GetAllData(string id, string name)
{
List<ScanCondition> conditions = new List<ScanCondition>();
conditions.Add(new ScanCondition("Id", ScanOperator.Equal, id));
conditions.Add(new ScanCondition("Name", ScanOperator.Equal, name));
var response = await _dynamoDbManager.GetAsync(conditions);
return Ok(response.ToList());
}
}
My above code works fine, its just that when the data in the table gets too large the operation becomes very slow. I was told by someone to look into QueryAsync method instead of ScanAsync as Scan method scans the entire table and is slow.
I looked at QueryAsync method and checked that it takes in hashkey as one of the parameter.
My Question is how can I make use of QueryAsync instead of ScanAsync with my code above. I am calling the above endpoint from my UI and it passes different params to scanconditions and filters there. How can I pass these conditions to the QueryAsync method.
Would appreciate inputs