Skip to content
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

MyModel.find_by_x(val).count seems to always return the global, unfiltered count #3

Open
slash4 opened this issue Apr 27, 2017 · 7 comments

Comments

@slash4
Copy link
Contributor

slash4 commented Apr 27, 2017

Hi @stakach , I'm playing with this lib and everything works nicely except 2 strange things :

  • When using find_by helpers, count seems to always return the global, unfiltered count, even if there's no result matching the filter.
  • If we try to use built-in reducers like _count, it's not possible to read the result :
    FFI::NullPointerError: invalid memory read at address=0x00000000000000 from /usr/local/bundle/gems/libcouchbase-0.1.0/lib/libcouchbase/query_view.rb:98:in []'`

Any thoughts ?

@slash4
Copy link
Contributor Author

slash4 commented Apr 27, 2017

OK answered to my second question myself, by passing include_docs: false the gem does not try to unserialize the document and, this is OK :)

@slash4 slash4 changed the title MyModel.find_by_x(val).count seems to always return 2 MyModel.find_by_x(val).count seems to always return the global, unfiltered count Apr 27, 2017
@stakach
Copy link
Contributor

stakach commented May 1, 2017

Yes.. unfortunately this is a couchbase level issue.
The count is always returned as the global unfiltered count by couchbase.

Which I agree is really annoying. However I can't think of any way to get the count except by making the full request and counting the documents returned. Which is not something we want to do if the result size is huge (not efficient all)

@stakach
Copy link
Contributor

stakach commented May 1, 2017

@avsej is there any way to obtain the count for a filtered query on a view?

@avsej
Copy link

avsej commented May 1, 2017

No, you get number of results in current response without actually parsing the "rows" array.

@stakach
Copy link
Contributor

stakach commented May 1, 2017

@avsej yeah, I'm using the total_rows metadata
Similar query regarding this https://forums.couchbase.com/t/query-returns-a-value-for-total-rows-but-with-an-empty-rows-array/3095

It makes sense that it doesn't return the total for the current filter as it would be difficult to compute cheaply.

@slash4
Copy link
Contributor Author

slash4 commented May 2, 2017

I got this right by using a dedicated map/reduce. I hesitate, should we add this as a default couchbase-orm behavior (with built in view and count method) ? Or maybe as an option, to avoid the creation of the view if you don't need the feature. I'll make a proposal.

@stakach
Copy link
Contributor

stakach commented May 2, 2017

@slash4 that does sound like an interesting and useful option! I'd be interested to take a look

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

No branches or pull requests

3 participants