Skip to content

A good pattern for counting a query in a reactive way #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mitar opened this issue Dec 18, 2014 · 3 comments
Open

A good pattern for counting a query in a reactive way #31

mitar opened this issue Dec 18, 2014 · 3 comments

Comments

@mitar
Copy link

mitar commented Dec 18, 2014

Current common pattern for counting a query in a reactive way is to create an observe and then first count all documents in initial blocking stage, and then keep the count updated as changes happen (room counting example). This is problematic for large collections and large resultsets.
#30 proposes some generic way to maybe address this, but there are maybe also some specialized ways for which I am opening this ticket.

@dandv
Copy link
Member

dandv commented Dec 19, 2014

It would help to mention how the pattern in publish-counts by @tmeasday, @dburles and @zoltan should be improve by core.

@tmeasday
Copy link

I think publish-counts is totally fine for smaller numbers (we use it for atmosphere's total # of packages, and I'm thinking that's starting to get too high).

For larger numbers, I've always thought there should be a way to do it using the low level oplog operations. You take a count(), then simply watch the oplog for i ops (or whatever they are called). There'll be edge cases around matching the timing of when you start reading the oplog and the time you took the count, but possibly that's not a big deal for most use cases. If not, then you might have to fetch the documents to be sure. Then you are stuck.

I've no idea how to do that but it seems like the tools should be there somewhere in the oplog code.

@mitar
Copy link
Author

mitar commented Dec 19, 2014

For larger numbers, I've always thought there should be a way to do it using the low level oplog operations.

Yes, but we (as end developers) should not have to parse oplog by ourselves, but should be able to use an existing API for that (like #30). Or maybe this should be provided as a special operation by core. Like observeCount. (I would also like to see observeExists, #46).

There'll be edge cases around matching the timing of when you start reading the oplog and the time you took the count, but possibly that's not a big deal for most use cases. If not, then you might have to fetch the documents to be sure. Then you are stuck.

Yes, in core that could probably be handled somehow. To match precisely the timing between initial .count() and oplog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants