4
I’m trying to pay for a consultation on Azure Cosmos DB
, reading this post: Paging through query Results in Azure Documentdb, got to the code:
public async Task <ICollection <TEntity>> GetAllPaged(int page, string colletionId) {
FeedOptions queryOptions = new FeedOptions {
MaxItemCount = 10
};
var query = client.CreateDocumentQuery <TEntity> (
UriFactory.CreateDocumentCollectionUri(databaseId, colletionId), queryOptions)
.AsDocumentQuery();
FeedResponse <TEntity> result;
List <TEntity> tEntitys = new List <TEntity> ();
int interacoes = 0;
while (query.HasMoreResults) {
interacoes++;
if (interacoes == page) {
result = await query.ExecuteNextAsync <TEntity> ();
tEntitys = result.ToList();
break;
}
}
return tEntitys;
}
Explaining:
MaxItemCount = 10
, total items per page.while (query.HasMoreResults)
, perform aloop
until there are results.if (interacoes == page)
, when you get to my page I no longer need to check the next ones, where thebreak
.
Problem:
Imagine that I have about 50002 documents, and that my page asks the method the result of number 5001, ie the last 2 records.
To each interaction of while
that code:result = await query.ExecuteNextAsync<TEntity>()
is responsible for each results page.
I thought to run this code only on the specific page I need through this code :if (interacoes == page)
, the problem of this is that only the first result is read, ie I need to read page by page to achieve the desired result described in the above scenario, and this has generated me 15 seconds of performance.
Note: Skip
is not supported because it offers a bad performance. More Issues of the Github!
Is the question astronomy? : P :D
– Maniero
@Maniero gives a strength ai :)rs!
– Marconi
I don’t know about that :)
– Maniero