TonyGen / mongoDB-haskell

MongoDB driver for Haskell
http://hackage.haskell.org/package/mongoDB
Apache License 2.0
57 stars 14 forks source link

Fix for issue #10 (updated) #12

Closed mkscrg closed 12 years ago

mkscrg commented 12 years ago

See issue #10.

Database.MongoDB.Query.next and nextBatch prefetch a promise of the next batch of documents from the server whenever the current batch has been exhausted. The following call to next or nextBatch fulfills that promise (thereby turning it into a concrete batch of documents) and then returns one or more documents in the batch.

The old behavior was to raise an exception if an empty batch with a nonzero cursor ID was encountered. This is normal when using tailable cursors, so a change was required.

Now, Nothing is returned with the still-live cursor ID, instead of raising the exception. Also, prefetched empty batches with nonzero cursor IDs are refetched once per call to avoid stale data.

This new prefetching behavior does not affect the performance of next, except when calling it repeatedly on a tailable cursor with no new data. In those (generally avoidable) cases, each call to next results in two server calls instead of one.

TonyGen commented 12 years ago

Thanks Michael for all your work on this. I will check it out and merge it tomorrow. Cheers.

TonyGen commented 12 years ago

A user found a bug in monad-control, so I'm postponing creating another release until it is fixed. See https://github.com/basvandijk/lifted-base/issues/1

mkscrg commented 12 years ago

No problem. Thanks for the heads up.

mkscrg commented 12 years ago

Looks like Bas has the fixed lifted-base on Hackage now. Can you get these tailable cursor fixes up too?

Cheers, Mike

TonyGen commented 12 years ago

I just released a new version with your fix. Thanks!