Eager load badge_def with badge.

Removes N guaranteed queries when rendering a userpage for a user with
N badges. We need the badge_def to provide nearly all properties of a
Badge, and it's nearly free with a one-to-one on indexed columns.
remotes/1693176582716663532/tmp_refs/heads/watchparty
Snakes 2022-11-09 09:25:47 -05:00
parent ebb3957f41
commit c9aee3ebb8
Signed by: Snakes
GPG Key ID: E745A82778055C7E
1 changed files with 1 additions and 1 deletions

View File

@ -37,7 +37,7 @@ class Badge(Base):
created_utc = Column(Integer)
user = relationship("User", back_populates="badges")
badge = relationship("BadgeDef", primaryjoin="Badge.badge_id == BadgeDef.id")
badge = relationship("BadgeDef", primaryjoin="Badge.badge_id == BadgeDef.id", lazy="joined", innerjoin=True)
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: