Eager load get_posts for submission_listings.
Ported in logic from upstream to use SQLAlchemy eager loading instead of repeated queries when building a submission_listing. Adjusted loaded relationships to include only those used on TheMotte. Using test data from seed_db, before and after: GET / |----------|--------|--------|--------|--------|--------|------------| | Database | SELECT | INSERT | UPDATE | DELETE | Totals | Duplicates | |----------|--------|--------|--------|--------|--------|------------| | default | 83 | 0 | 0 | 0 | 83 | 72 | |----------|--------|--------|--------|--------|--------|------------| Total queries: 83 in 0.031s GET / |----------|--------|--------|--------|--------|--------|------------| | Database | SELECT | INSERT | UPDATE | DELETE | Totals | Duplicates | |----------|--------|--------|--------|--------|--------|------------| | default | 14 | 0 | 0 | 0 | 14 | 0 | |----------|--------|--------|--------|--------|--------|------------| Total queries: 14 in 0.00718s
This commit is contained in:
parent
9953c5763c
commit
4d22d9bce2
5 changed files with 24 additions and 10 deletions
|
@ -33,7 +33,9 @@ class Badge(Base):
|
|||
Index('badges_badge_id_idx', badge_id)
|
||||
|
||||
user = relationship("User", viewonly=True)
|
||||
badge = relationship("BadgeDef", primaryjoin="foreign(Badge.badge_id) == remote(BadgeDef.id)", viewonly=True)
|
||||
badge = relationship("BadgeDef",
|
||||
primaryjoin="foreign(Badge.badge_id) == remote(BadgeDef.id)",
|
||||
lazy="joined", innerjoin=True, viewonly=True)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Badge(user_id={self.user_id}, badge_id={self.badge_id})>"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue