otakulan / lanparty-seating

Webapp to manage seating at Otakuthon PC Gaming
6 stars 1 forks source link

Optimize SQL query that fetches the status of every station #33

Closed starcraft66 closed 1 year ago

starcraft66 commented 1 year ago

In https://github.com/starcraft66/lanparty-seating/blob/master/lib/lanpartyseating/logic/station_logic.ex, we start by querying all of the stations in the repo on line 16, then for every station, we call get_station_status/1 on them which results in 3 SQL queries being executed per station. This is very expensive and causes the page to be noticeably slow even with postgres running on an SSD on localhost.

All of the logic in there needs to be refactored into a single SQL query that joins the Station with Reservation and TournamentReservation to find all of the stations and their status.

starcraft66 commented 1 year ago

Completed in https://github.com/starcraft66/lanparty-seating/pull/34