Skip to content

Commit

Permalink
move ts_db_entries and ts_db_count into if/else block
Browse files Browse the repository at this point in the history
  • Loading branch information
JGreenlee committed Mar 3, 2025
1 parent 8292b3d commit 5c70655
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions emission/storage/timeseries/builtin_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,18 @@ def _get_entries_for_timeseries(self, tsdb, key_list, time_query, geo_query,
# In [593]: edb.get_timeseries_db().find({"user_id": UUID('ea59084e-11d4-4076-9252-3b9a29ce35e0')}).count()
# Out[593]: 449869
ts_db_result.limit(edb.result_limit)

# This list() conversion causes the cursor to be consumed, which is memory-expensive,
# but faster as it allows us to get the count without having to make an additional
# "count_documents" DB call.
# In a future situation where memory is constrained or DB calls are less expensive,
# we could skip the list() conversion and return the cursor directly.
# https://github.com/e-mission/e-mission-server/pull/1032#issuecomment-2685846702
ts_db_entries = list(ts_db_result)
ts_db_count = len(ts_db_entries)
else:
ts_db_result = []

# This list() conversion causes the cursor to be consumed, which is memory-expensive,
# but faster as it allows us to get the count without having to make an additional
# "count_documents" DB call.
# In a future situation where memory is constrained or DB calls are less expensive,
# we could skip the list() conversion and return the cursor directly.
# https://github.com/e-mission/e-mission-server/pull/1032#issuecomment-2685846702
ts_db_entries = list(ts_db_result)
ts_db_count = len(ts_db_entries)
ts_db_entries = []
ts_db_count = 0

logging.debug("finished querying values for %s, count = %d" % (key_list, ts_db_count))
return (ts_db_count, ts_db_entries)
Expand Down

0 comments on commit 5c70655

Please sign in to comment.