Skip to content

Commit

Permalink
don't await fetch calls
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYps committed Jun 4, 2024
1 parent 28b4ccf commit 4e58a15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions service/league_service/league_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def update_data(self):
.where(between(datetime.now(), league_season.c.start_date, league_season.c.end_date))
)
result = await conn.execute(sql)
division_rows = await result.fetchall()
division_rows = result.fetchall()

# The concept of subdivisions exists only in the database and client,
# but not in the rating service. We therefore treat every subdivision
Expand Down Expand Up @@ -152,7 +152,7 @@ async def _load_score(self, player_id: PlayerID, league: League) -> LeagueScore:
)
)
result = await conn.execute(sql)
row = await result.fetchone()
row = result.fetchone()
if row is None:
returning_player = await self.is_returning_player(player_id, league.rating_type)
return LeagueScore(None, None, 0, returning_player)
Expand All @@ -179,7 +179,7 @@ async def is_returning_player(self, player_id: PlayerID, rating_type: str) -> bo
)
)
result = await conn.execute(sql)
row = await result.fetchone()
row = result.fetchone()
if row is None or row[league_season_score.c.subdivision_id] is None:
return False
else:
Expand Down Expand Up @@ -211,7 +211,7 @@ async def _persist_score(
)
)
result = await conn.execute(select_season_id)
row = await result.fetchone()
row = result.fetchone()
season_id_of_division = row.get("league_season_id")
if season_id != season_id_of_division:
raise InvalidScoreError("Division id did not match season id.")
Expand Down
14 changes: 7 additions & 7 deletions service/season_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def check_season_end(self):
async with self._db.acquire() as conn:
sql = select(league_season)
result = await conn.execute(sql)
rows = await result.fetchall()
rows = result.fetchall()

max_date = max(row[league_season.c.end_date] for row in rows)

Expand All @@ -45,7 +45,7 @@ async def generate_season(self):
async with self._db.acquire() as conn:
sql = select(league).where(league.c.enabled == True)
result = await conn.execute(sql)
rows = await result.fetchall()
rows = result.fetchall()

next_month = datetime.now() + relativedelta(months=1)
# season starts and ends at noon, so that all timezones see the same date in the client
Expand All @@ -63,15 +63,15 @@ async def update_db(self, conn, league_row, start_date, end_date):
.limit(1)
)
result = await conn.execute(season_sql)
season_row = await result.fetchone()
season_row = result.fetchone()
if season_row is None:
self._logger.warning(
"No season found for league %s. Skipping this league",
league_row[league.c.technical_name]
)
return
result = await conn.execute(select(func.max(league_season.c.id)))
season_id = await result.scalar() + 1
season_id = result.scalar() + 1
season_number = season_row[league_season.c.season_number] + 1
season_insert_sql = (
insert(league_season)
Expand All @@ -93,7 +93,7 @@ async def update_db(self, conn, league_row, start_date, end_date):
.where(league_season_division.c.league_season_id == season_row[league_season.c.id])
)
result = await conn.execute(division_sql)
season_division_rows = await result.fetchall()
season_division_rows = result.fetchall()
if not season_division_rows:
self._logger.warning(
"No divisions found for season id %s. No divisions could be created. "
Expand All @@ -103,7 +103,7 @@ async def update_db(self, conn, league_row, start_date, end_date):
)
return
result = await conn.execute(select(func.max(league_season_division.c.id)))
division_id = await result.scalar()
division_id = result.scalar()
for division_row in season_division_rows:
division_index = division_row[league_season_division.c.division_index]
division_id += 1
Expand All @@ -127,7 +127,7 @@ async def update_db(self, conn, league_row, start_date, end_date):
division_row[league_season_division.c.id])
)
result = await conn.execute(subdivision_sql)
subdivision_rows = await result.fetchall()
subdivision_rows = result.fetchall()
if not subdivision_rows:
self._logger.warning(
"No subdivisions found for division id %s. No subdivisions could be created. "
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_league_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async def test_persist_score_new_player(league_service, database):

async with database.acquire() as conn:
result = await conn.execute(select(league_score_journal))
rows = await result.fetchall()
rows = result.fetchall()
assert len(rows) == 1
for row in rows:
assert row["game_id"] == 1
Expand Down Expand Up @@ -216,7 +216,7 @@ async def test_persist_score_old_player(league_service, database):

async with database.acquire() as conn:
result = await conn.execute(select(league_score_journal))
rows = await result.fetchall()
rows = result.fetchall()
assert len(rows) == 1
for row in rows:
assert row["game_id"] == 10
Expand Down

0 comments on commit 4e58a15

Please sign in to comment.