Skip to content

Commit 312f46a

Browse files
authored
Allow the first page of MongoDB results to very slowly return a proper count (#2253)
1 parent 3c4f5b5 commit 312f46a

File tree

1 file changed

+3
-0
lines changed
  • optimade/server/entry_collections

1 file changed

+3
-0
lines changed

optimade/server/entry_collections/mongo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ def _run_db_query(
195195
criteria_nolimit = criteria.copy()
196196
criteria_nolimit.pop("limit", None)
197197
skip = criteria_nolimit.pop("skip", 0)
198+
# If we're on the first page, set a much higher timeout for counting the results (10 s)
199+
if skip == 0:
200+
criteria_nolimit["maxTimeMS"] = 1000 * 10
198201
data_returned = self.count(**criteria_nolimit)
199202
# Only correct most of the time: if the total number of remaining results is exactly the page limit
200203
# then this will incorrectly say there is more_data_available

0 commit comments

Comments
 (0)