Skip to content

Commit

Permalink
Try to speed up cfp-review by getting the database to count tagged pr…
Browse files Browse the repository at this point in the history
…oposals

Previously we were fetching every proposal containing each tag type in a
separate query, where we actually just want the global count of proposals with
a particular tag.
  • Loading branch information
lukegb committed May 22, 2024
1 parent ba0f183 commit 13696f9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions apps/cfp_review/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
Venue,
WorkshopProposal,
)
from models.cfp_tag import Tag
from models.cfp_tag import Tag, ProposalTag
from models.user import User
from models.purchase import Ticket
from .forms import (
Expand Down Expand Up @@ -188,7 +188,16 @@ def proposals():
if "reverse" in non_sort_query_string:
del non_sort_query_string["reverse"]

tag_counts = {t.tag: [0, len(t.proposals)] for t in Tag.query.all()}
tag_counts = dict(
db.session
.query(Tag.tag, db.func.count(ProposalTag.c.proposal_id))
.select_from(Tag)
.outerjoin(ProposalTag)
.group_by(Tag.tag)
.order_by(Tag.tag)
.all()
)
tag_counts = {tag: [0, prop_count] for tag, prop_count in tag_counts.items()}
for prop in proposals:
for t in prop.tags:
tag_counts[t.tag][0] = tag_counts[t.tag][0] + 1
Expand Down

0 comments on commit 13696f9

Please sign in to comment.