mozilla/elasticutils — pull request #212 by nearlyfreeapps (2014-03-04 02:59:03+00:00)
Title: Ensure results cache is used even if there were no results

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 not `None`.