Optimize database interactions and migrate to SQLAlchemy 2#799
Open
jack89roberts wants to merge 15 commits intodevelopfrom
Open
Optimize database interactions and migrate to SQLAlchemy 2#799jack89roberts wants to merge 15 commits intodevelopfrom
jack89roberts wants to merge 15 commits intodevelopfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vibe coded all the way... will do more comparisons with develop but it seems to be a decent speedup.
This pull request refactors many database queries throughout the codebase to use SQLAlchemy 2.x's
select()andscalars()APIs instead of the legacyquery()API. The changes improve performance, reliability, and future compatibility, and in several places also optimize data access by prefetching related objects or batching queries. Additionally, some relationships in the schema are updated for more efficient loading and ordering.Database Query Refactoring and Optimization
.query()API with.scalars(select(...))and.execute(select(...))in most database access patterns across the codebase, including inairsenal/conftest.py,airsenal/framework/api_utils.py,airsenal/framework/aws_utils.py,airsenal/framework/bpl_interface.py,airsenal/framework/optimization_utils.py, andairsenal/framework/prediction_utils.py. This modernizes the codebase for SQLAlchemy 2.x and improves query performance.selectinload) and avoid N+1 query issues, especially in player and fixture data access.Performance and Data Access Improvements
build_suggestion_string,get_session_players, andget_player_history_df).Schema and Relationship Enhancements
Playermodel'sattributesrelationship to uselazy="selectin"and to order by season and gameweek descending, improving both query efficiency and result ordering when accessing player attributes.Index,UniqueConstraint, andselectinschema.pyto support new schema and query patterns.These changes collectively modernize the codebase, improve performance, and set the foundation for future SQLAlchemy compatibility.