Skip to content

Commit

Permalink
skip unnecessary query
Browse files Browse the repository at this point in the history
  • Loading branch information
ppigazzini committed Apr 27, 2024
1 parent 2f9066f commit 13a98ff
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions server/fishtest/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ def get_pgn(self, run_id):
return pgn["pgn_zip"] if pgn else None

def get_run_pgns(self, run_id):
pgns = self.pgndb.find({"run_id": {"$regex": f"^{run_id}-\\d+"}})
# Compute the total size using MongoDB's aggregation framework
total_size_agg = self.pgndb.aggregate(
[
Expand All @@ -276,12 +275,14 @@ def get_run_pgns(self, run_id):
]
)
total_size = total_size_agg.next()["totalSize"] if total_size_agg.alive else 0
# Create a generator that yields each pgn.gz file
pgn_generator = (
GeneratorAsFileReader(pgn["pgn_zip"] for pgn in pgns)
if total_size
else None
)

if total_size > 0:
# Find the pgns and create a generator that yields each pgn.gz file
pgns = self.pgndb.find({"run_id": {"$regex": f"^{run_id}-\\d+"}})
pgn_generator = GeneratorAsFileReader(pgn["pgn_zip"] for pgn in pgns)
else:
pgn_generator = None

return pgn_generator, total_size

def write_nn(self, net):
Expand Down

0 comments on commit 13a98ff

Please sign in to comment.