From 591ab8f6d3589a4bec52f6c0a5d9b819127e7a5c Mon Sep 17 00:00:00 2001 From: fullsizemalt <106900403+fullsizemalt@users.noreply.github.com> Date: Sun, 21 Dec 2025 03:22:59 -0800 Subject: [PATCH] fix: Correct leaderboards queries to use proper Rating FKs --- backend/routers/leaderboards.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/backend/routers/leaderboards.py b/backend/routers/leaderboards.py index ace4e49..17a50cb 100644 --- a/backend/routers/leaderboards.py +++ b/backend/routers/leaderboards.py @@ -22,7 +22,7 @@ def get_top_shows(limit: int = 10, session: Session = Depends(get_session)): ) .join(Rating, Rating.show_id == Show.id) .join(Venue, Show.venue_id == Venue.id) - .where(Rating.entity_type == "show") + # Rating FK already filters via join .group_by(Show.id, Venue.id) .having(func.count(Rating.id) >= 1) .order_by(desc("avg_score"), desc("rating_count")) @@ -57,7 +57,7 @@ def get_top_performances(limit: int = 20, session: Session = Depends(get_session .join(Song, Performance.song_id == Song.id) .join(Show, Performance.show_id == Show.id) .join(Venue, Show.venue_id == Venue.id) - .where(Rating.entity_type == "performance") + # Rating FK already filters via join .group_by(Performance.id, Song.id, Show.id, Venue.id) .having(func.count(Rating.id) >= 1) .order_by(desc("avg_score"), desc("rating_count")) @@ -80,19 +80,16 @@ def get_top_performances(limit: int = 20, session: Session = Depends(get_session @router.get("/venues/top") def get_top_venues(limit: int = 10, session: Session = Depends(get_session)): - """Get top rated venues based on show ratings there?""" - # A venue's rating is often derivative of the shows there, or specific venue ratings. - # Let's assume venue rating directly for now if entity_type='venue' exists, - # otherwise we might avg show ratings. Let's start with direct venue ratings. - + """Get top rated venues based on show ratings there""" + # Aggregate ratings from shows played at each venue query = ( select( Venue, func.avg(Rating.score).label("avg_score"), func.count(Rating.id).label("rating_count") ) - .join(Rating, Rating.venue_id == Venue.id) - .where(Rating.entity_type == "venue") + .join(Show, Show.venue_id == Venue.id) + .join(Rating, Rating.show_id == Show.id) .group_by(Venue.id) .having(func.count(Rating.id) >= 1) .order_by(desc("avg_score")) @@ -101,9 +98,6 @@ def get_top_venues(limit: int = 10, session: Session = Depends(get_session)): results = session.exec(query).all() - # Fallback: if no direct venue ratings, maybe average the shows played there? - # Keeping it simple for now. - return [ { "venue": venue,