Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RavenDB Paging Behaviour

Tags:

ravendb

I have the following test for skip take -

    [Test]
    public void RavenPagingBehaviour()
    {
        const int count = 2048;
        var eventEntities = PopulateEvents(count);
        PopulateEventsToRaven(eventEntities);

        using (var session = Store.OpenSession(_testDataBase))
        {
            var queryable =
                session.Query<EventEntity>().Customize(x => x.WaitForNonStaleResultsAsOfLastWrite()).Skip(0).Take(1024);

            var entities = queryable.ToArray();

            foreach (var eventEntity in entities)
            {
                eventEntity.Key = "Modified";
            }

            session.SaveChanges();

            queryable = session.Query<EventEntity>().Customize(x => x.WaitForNonStaleResultsAsOfLastWrite()).Skip(0).Take(1024);

            entities = queryable.ToArray();

            foreach (var eventEntity in entities)
            {
                Assert.AreEqual(eventEntity.Key, "Modified");
            }
        }
    }

PopulateEventsToRaven simply adds 2048 very simple documents to the database.

The first skip take combination gets the first 1024 doucuments modifies the documents and then commits changes.

The next skip take combination again wants to get the first 1024 documents but this time it gets the document number 1024 to 2048 and hence fails the test. Why is this , I would expect the first 1024 again?

Edit: I have varified that if I dont modify the documents the behaviour is fine.

like image 262
NiladriBose Avatar asked Feb 03 '23 14:02

NiladriBose


1 Answers

The problem is that you don't specify an order by, and that means that RavenDB is free to choose with items to return, those aren't necessarily going to be the same items that it returned in the previous call. Use an OrderBy and it will be consistent.

like image 131
Ayende Rahien Avatar answered Mar 16 '23 00:03

Ayende Rahien