Skip to content

Commit

Permalink
Switch relationship loading to selectionload (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminalaee authored May 12, 2024
1 parent 8b193fe commit 9b1eff0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions sqladmin/_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import anyio
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import Session, joinedload
from sqlalchemy.orm import Session, selectinload
from sqlalchemy.sql.expression import Select, and_, or_
from starlette.requests import Request

Expand Down Expand Up @@ -152,7 +152,7 @@ async def _update_async(
stmt = self.model_view._stmt_by_identifier(pk)

for relation in self.model_view._form_relations:
stmt = stmt.options(joinedload(relation))
stmt = stmt.options(selectinload(relation))

async with self.model_view.session_maker(expire_on_commit=False) as session:
result = await session.execute(stmt)
Expand Down
10 changes: 5 additions & 5 deletions sqladmin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import anyio
from sqlalchemy import Column, String, asc, cast, desc, func, inspect, or_
from sqlalchemy.exc import NoInspectionAvailable
from sqlalchemy.orm import joinedload, sessionmaker
from sqlalchemy.orm import selectinload, sessionmaker
from sqlalchemy.orm.exc import DetachedInstanceError
from sqlalchemy.sql.elements import ClauseElement
from sqlalchemy.sql.expression import Select, select
Expand Down Expand Up @@ -772,7 +772,7 @@ async def list(self, request: Request) -> Pagination:

stmt = self.list_query(request)
for relation in self._list_relations:
stmt = stmt.options(joinedload(relation))
stmt = stmt.options(selectinload(relation))

stmt = self.sort_query(stmt, request)

Expand Down Expand Up @@ -802,7 +802,7 @@ async def get_model_objects(
stmt = self.list_query(request).limit(limit)

for relation in self._list_relations:
stmt = stmt.options(joinedload(relation))
stmt = stmt.options(selectinload(relation))

rows = await self._run_query(stmt)
return rows
Expand All @@ -815,7 +815,7 @@ async def get_object_for_details(self, value: Any) -> Any:
stmt = self._stmt_by_identifier(value)

for relation in self._details_relations:
stmt = stmt.options(joinedload(relation))
stmt = stmt.options(selectinload(relation))

return await self._get_object_by_pk(stmt)

Expand Down Expand Up @@ -1062,7 +1062,7 @@ def edit_form_query(self, request: Request) -> Select:

stmt = self._stmt_by_identifier(request.path_params["pk"])
for relation in self._form_relations:
stmt = stmt.options(joinedload(relation))
stmt = stmt.options(selectinload(relation))
return stmt

def count_query(self, request: Request) -> Select:
Expand Down

0 comments on commit 9b1eff0

Please sign in to comment.