Hi
I'm building an application that is online only part of the time, and thus uses a briefcase pattern. All data is synced when the client application is online, available for use when offline.
moving parts
- clientapp = .net maui application sitting on top of an embedded raven db
- server = website that sits on top of a cloud instance of raven db.
the data I need to sync is basically
class Product{
public string Id => "products|";
public DateTime LastModified => DateTime.UtcNow;
// lots of business data here
}
the product catalog contains 1000s of products, some of which are bulk uploaded into the database (and thus have the same LastModified date).
The API to read out the products is paged - returning 100 or so products per call
The problem i'm facing now is building a reliable paging system for the data.
The most naive version of this is something along the lines of
var products = await session.Query<Product>()
.Where(p => p.LastModified > previousLastModified)
.OrderBy(e => p.LastModified)
.Take(pageSize)
.ToListAsync();
which obviously doesn't work due to bulk updates and many items having the same last modified.
In a world with numerical document Ids I could do something like this
var productsWithSameLastModified = await session.Query<Product>()
.Where(p => p.LastModified = previousLastModified && p.Id > previousLastId)
.OrderBy(e => p.Id)
.Take(pageSize)
.ToListAsync();
var products = await session.Query<Product>()
.Where(p => p.LastModified > previousLastModified)
.OrderBy(e => p.LastModified).ThenBy(p => p.Id)
.Take(pageSize -
productsWithSameLastModified.Count() )
.ToListAsync();
var result = productsWithSameLastModified.Union(products);
But given that all documents are string Ids - seems a bit counter intuitive?
Long story short - is there a better / simpler way of doing this?