fix: skip total_count query for CSV requests and consolidate rewards.py counts

- Guard total_count with `if not csv` ternary to avoid unnecessary
  COUNT query on CSV export paths (10 files)
- Consolidate rewards.py from 3 COUNT queries to 1 (used for both
  empty-check and response)
- Clean up scout_claims.py double `if limit is not None` block
- Normalize scout_opportunities.py from max(1,...) to max(0,...)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-03-24 07:43:14 -05:00
parent 54dccd1981
commit 1e21894898
13 changed files with 14 additions and 19 deletions

View File

@ -55,7 +55,7 @@ async def get_awards(
all_awards = all_awards.where(Award.image == image)
limit = max(0, min(limit, 500))
total_count = all_awards.count()
total_count = all_awards.count() if not csv else 0
all_awards = all_awards.limit(limit)
if csv:

View File

@ -115,7 +115,7 @@ async def get_batstats(
# raise HTTPException(status_code=404, detail=f'No batting stats found')
limit = max(0, min(limit, 500))
total_count = all_stats.count()
total_count = all_stats.count() if not csv else 0
all_stats = all_stats.limit(limit)
if csv:

View File

@ -179,7 +179,7 @@ async def get_card_ratings(
)
all_ratings = all_ratings.where(BattingCardRatings.battingcard << set_cards)
total_count = all_ratings.count()
total_count = all_ratings.count() if not csv else 0
all_ratings = all_ratings.limit(max(0, min(limit, 500)))
if csv:

View File

@ -40,7 +40,7 @@ async def v1_events_get(
if active is not None:
all_events = all_events.where(Event.active == active)
total_count = all_events.count()
total_count = all_events.count() if not csv else 0
all_events = all_events.limit(max(0, min(limit, 500)))
if csv:

View File

@ -43,7 +43,7 @@ async def v1_gamerewards_get(
all_rewards = all_rewards.where(GameRewards.money == money)
limit = max(0, min(limit, 500))
total_count = all_rewards.count()
total_count = all_rewards.count() if not csv else 0
all_rewards = all_rewards.limit(limit)
if csv:

View File

@ -102,7 +102,7 @@ async def get_players(
if offense_col is not None:
all_players = all_players.where(MlbPlayer.offense_col << offense_col)
total_count = all_players.count()
total_count = all_players.count() if not csv else 0
all_players = all_players.limit(max(0, min(limit, 500)))
if csv:

View File

@ -169,7 +169,7 @@ async def get_card_ratings(
)
all_ratings = all_ratings.where(PitchingCardRatings.pitchingcard << set_cards)
total_count = all_ratings.count()
total_count = all_ratings.count() if not csv else 0
all_ratings = all_ratings.limit(max(0, min(limit, 500)))
if csv:

View File

@ -98,7 +98,7 @@ async def get_pit_stats(
if gs is not None:
all_stats = all_stats.where(PitchingStat.gs == 1 if gs else 0)
total_count = all_stats.count()
total_count = all_stats.count() if not csv else 0
all_stats = all_stats.limit(max(0, min(limit, 500)))
# if all_stats.count() == 0:

View File

@ -142,7 +142,7 @@ async def get_results(
all_results = all_results.order_by(Result.id)
limit = max(0, min(limit, 500))
total_count = all_results.count()
total_count = all_results.count() if not csv else 0
all_results = all_results.limit(limit)
# Not functional
# if vs_ai is not None:

View File

@ -34,9 +34,6 @@ async def get_rewards(
):
all_rewards = Reward.select().order_by(Reward.id)
if all_rewards.count() == 0:
raise HTTPException(status_code=404, detail="There are no rewards to filter")
if name is not None:
all_rewards = all_rewards.where(fn.Lower(Reward.name) == name.lower())
if team_id is not None:
@ -52,11 +49,11 @@ async def get_rewards(
if week is not None:
all_rewards = all_rewards.where(Reward.week == week)
if all_rewards.count() == 0:
total_count = all_rewards.count()
if total_count == 0:
raise HTTPException(status_code=404, detail="No rewards found")
limit = max(0, min(limit, 500))
total_count = all_rewards.count()
all_rewards = all_rewards.limit(limit)
if csv:

View File

@ -30,12 +30,10 @@ async def get_scout_claims(
if claimed_by_team_id is not None:
query = query.where(ScoutClaim.claimed_by_team_id == claimed_by_team_id)
if limit is not None:
limit = max(0, min(limit, 500))
total_count = query.count()
if limit is not None:
limit = max(0, min(limit, 500))
query = query.limit(limit)
results = [model_to_dict(x, recurse=False) for x in query]

View File

@ -35,7 +35,7 @@ async def get_scout_opportunities(
limit: Optional[int] = 100,
):
limit = max(1, min(limit, 500))
limit = max(0, min(limit, 500))
query = ScoutOpportunity.select().order_by(ScoutOpportunity.id)
if opener_team_id is not None:

View File

@ -78,7 +78,7 @@ async def get_games(
StratGame.game_type.contains(f"gauntlet-{gauntlet_id}")
)
total_count = all_games.count()
total_count = all_games.count() if not csv else 0
all_games = all_games.limit(max(0, min(limit, 500)))
if csv: