Closed nearlyfreeapps closed 10 years ago
I'll look at this for 0.9 later this week.
I'm kind of puzzled, though. I thought we had fixed this already, but maybe it was a related thing and not this particular thing. I'll be enlightened when I scrutinize further.
I can confirm that this does fix the bug we're looking at.
The count
does a boolean check on self._results_cache
, which in the case I'm looking at is a elasticutils.DictSearchResults object
. The boolean check triggers a __len__
as mentioned. The length comes back zero which results in a False
. So it does the query with a slice resulting in a 2nd ES hit.
Applying this patch fixes it and returns the count from the _result_cache
.
Looks good to me. Thank you!
On Marketplace, we determined that we were making two requests to Elasticsearch whenever we had a search that returned no results. From some debugging I believe this is because of the way that
self._results_cache
is being evaluated here: https://github.com/mozilla/elasticutils/blob/master/elasticutils/__init__.py#L1450. In cases with no results, the__len__
method is being being evaluated to 0 which makes this statement falsey (and triggers another request).This will simply explicitly check if the
self._results_cache
is notNone
.