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:
TLSM 2022-11-28 12:55:31 -05:00
parent 9953c5763c
commit 4d22d9bce2
No known key found for this signature in database
GPG key ID: E745A82778055C7E
5 changed files with 24 additions and 10 deletions

View file

@ -160,7 +160,7 @@ def searchposts(v):
next_exists = (len(ids) > 25)
ids = ids[:25]
posts = get_posts(ids, v=v)
posts = get_posts(ids, v=v, eager=True)
if request.headers.get("Authorization"): return {"total":total, "data":[x.json for x in posts]}