dimanche 28 juin 2015

Raven paging queries in a specific way

I'm developing an ASP.NET MVC application using RavenDB 3. I don't have a lot of experience with raven.

In general, when executing queries to display data, the first 128 items are returned on the page. More records are added in an "infinite scroll"-manner by using paged queries.

Now, however, I have the requirement that items are loaded in 'groups'.

Assume the following class:

public class Item {
  public string Id { get; set; }
  public int Group { get; set; }
  public string text { get; set; }
}

Assume the database contains 40 items having group='1', 40 items having group='2' and 50 items having group='3'.

This is a total of 130 items. This would mean that the last 'group' fetched would not be complete. It would be missing 2 items.

I would like a mechanism that is aware of this, so that it would fetch at least 128 AND would fetch 'extra' if the last group is not completely included.

Afterwards, when I fetch the next page, I would like it to start with the next group.

Is there any way I can make this work without 'fabricating' a single page myself by doing more than one call?

EDIT: I cannot assume the groups are perfectly equal in size, but I can assume the sizes will be 'simular'

Also, I cannot change the design to store all items in a single 'group'-object for instance.

Aucun commentaire:

Enregistrer un commentaire