reduce repeat queries in GET /api/users

add eager loading of several relationships that are ~always used when the given objects are requested
add specific eager loading of spawners to the users query

- roles, groups (always needed to resolve permissions)
- APIToken.user, service
This commit is contained in:
Min RK
2023-06-27 09:25:33 +02:00
parent 715b8f3cee
commit f24fbc761f
2 changed files with 27 additions and 7 deletions

View File

@@ -263,7 +263,10 @@ class User(Base):
name = Column(Unicode(255), unique=True)
roles = relationship(
'Role', secondary='user_role_map', back_populates='users', lazy="selectin"
'Role',
secondary='user_role_map',
back_populates='users',
lazy="selectin",
)
_orm_spawners = relationship(
@@ -285,6 +288,7 @@ class User(Base):
"Group",
secondary='user_group_map',
back_populates="users",
lazy="selectin",
)
oauth_codes = relationship(
"OAuthCode", back_populates="user", cascade="all, delete-orphan"