Skip to content

Commit a8122ee

Browse files
committed
fix total by also counting deprecated docs
1 parent bcc977e commit a8122ee

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

mp_api/client/core/client.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import platform
1212
import sys
1313
import warnings
14+
import inspect
15+
1416
from concurrent.futures import FIRST_COMPLETED, ThreadPoolExecutor, wait
1517
from copy import copy
1618
from datetime import datetime
@@ -1272,29 +1274,40 @@ def count(self, criteria: dict | None = None) -> int | str:
12721274
Returns:
12731275
(int | str): Count of total results, or string indicating error
12741276
"""
1275-
try:
1276-
criteria = criteria or {}
1277-
user_preferences = (
1278-
self.monty_decode,
1279-
self.use_document_model,
1280-
self.mute_progress_bars,
1281-
)
1282-
self.monty_decode, self.use_document_model, self.mute_progress_bars = (
1283-
False,
1284-
False,
1285-
True,
1286-
) # do not waste cycles decoding
1287-
results = self._query_resource(
1288-
criteria=criteria, num_chunks=1, chunk_size=1
1289-
)
1290-
(
1291-
self.monty_decode,
1292-
self.use_document_model,
1293-
self.mute_progress_bars,
1294-
) = user_preferences
1295-
return results["meta"]["total_doc"]
1296-
except Exception: # pragma: no cover
1297-
return "Problem getting count"
1277+
criteria = criteria or {}
1278+
user_preferences = (
1279+
self.monty_decode,
1280+
self.use_document_model,
1281+
self.mute_progress_bars,
1282+
)
1283+
self.monty_decode, self.use_document_model, self.mute_progress_bars = (
1284+
False,
1285+
False,
1286+
True,
1287+
) # do not waste cycles decoding
1288+
results = self._query_resource(criteria=criteria, num_chunks=1, chunk_size=1)
1289+
cnt = results["meta"]["total_doc"]
1290+
1291+
no_query = not {field for field in criteria if field[0] != "_"}
1292+
if no_query and hasattr(self, "search"):
1293+
allowed_params = inspect.getfullargspec(self.search).args
1294+
if "deprecated" in allowed_params:
1295+
criteria["deprecated"] = True
1296+
results = self._query_resource(
1297+
criteria=criteria, num_chunks=1, chunk_size=1
1298+
)
1299+
cnt += results["meta"]["total_doc"]
1300+
warnings.warn(
1301+
"Omitting a query also includes deprecated documents in the results. "
1302+
"Make sure to post-filter them out."
1303+
)
1304+
1305+
(
1306+
self.monty_decode,
1307+
self.use_document_model,
1308+
self.mute_progress_bars,
1309+
) = user_preferences
1310+
return cnt
12981311

12991312
@property
13001313
def available_fields(self) -> list[str]:

0 commit comments

Comments
 (0)