Skip to content

Commit

Permalink
Eager loaded turns in vis runner (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanAEckelberg authored Jan 8, 2024
1 parent 43cc7ca commit 2473aaf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions server/crud/crud_tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,20 @@ def delete(db: Session, id: int) -> None:
db.commit()


def get_latest_tournament(db: Session) -> Tournament | None:
def get_latest_tournament(db: Session, with_turns: bool = False) -> Tournament | None:
return (db.query(Tournament)
.options(joinedload(Tournament.runs)
.joinedload(Run.submission_run_infos)
.joinedload(SubmissionRunInfo.submission)
.joinedload(Submission.team))
.order_by(Tournament.tournament_id.desc())
.first())
.first()) if not with_turns else \
(db.query(Tournament)
.options(joinedload(Tournament.runs)
.joinedload(Run.submission_run_infos)
.joinedload(SubmissionRunInfo.submission)
.joinedload(Submission.team),
joinedload(Tournament.runs)
.joinedload(Run.turns))
.order_by(Tournament.tournament_id.desc())
.first())
2 changes: 1 addition & 1 deletion server/visualizer_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_latest_log_files(self, tournament: Tournament) -> None:
def get_latest_tournament(self) -> Tournament | None:
print("Getting Latest Tournament")
with DB() as db:
return crud_tournament.get_latest_tournament(db) if not None else None
return crud_tournament.get_latest_tournament(db, with_turns=True) if not None else None

def visualizer_loop(self) -> None:
print('in visualizer_loop()')
Expand Down

0 comments on commit 2473aaf

Please sign in to comment.