Skip to content

Commit

Permalink
Merge pull request #358 from danielfromearth/feature/issue-357
Browse files Browse the repository at this point in the history
Feature/issue 357 closes #358
  • Loading branch information
betolink authored Nov 22, 2023
2 parents 7db2e59 + 290176a commit a0a58aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [unreleased]
* Fix zero granules being reported for restricted datasets

## [v0.7.1] 2023-11-08
* Bug Fixes:
* Treat granules without `RelatedUrls` as not cloud-hosted.
Expand Down
21 changes: 20 additions & 1 deletion earthaccess/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def hits(self) -> int:
Returns:
number of results reproted by CMR
number of results reported by CMR
"""
return super().hits()

Expand Down Expand Up @@ -318,6 +318,25 @@ def __init__(self, auth: Any = None, *args: Any, **kwargs: Any) -> None:

self._debug = False

def hits(self) -> int:
"""
Returns the number of hits the current query will return. This is done by
making a lightweight query to CMR and inspecting the returned headers.
:returns: number of results reported by CMR
"""

url = self._build_url()

response = self.session.get(url, headers=self.headers, params={"page_size": 0})

try:
response.raise_for_status()
except exceptions.HTTPError as ex:
raise RuntimeError(ex.response.text)

return int(response.headers["CMR-Hits"])

def parameters(self, **kwargs: Any) -> Type[CollectionQuery]:
"""Provide query parameters as keyword arguments. The keyword needs to match the name
of the method, and the value should either be the value or a tuple of values.
Expand Down

0 comments on commit a0a58aa

Please sign in to comment.