perf(aurweb/pkgbase): use exists() to avoid fetching a row

The previous approach fetched the matching row, by using `exists()`
SQLAlchemy changes the query to a `SELECT 1`.
This commit is contained in:
Jelle van der Waa 2024-08-09 13:01:54 +02:00
parent b65d6c5e3a
commit d1a66a743e
No known key found for this signature in database
GPG key ID: C06086337C50773E

View file

@ -73,8 +73,10 @@ def make_context(
context["out_of_date"] = bool(pkgbase.OutOfDateTS) context["out_of_date"] = bool(pkgbase.OutOfDateTS)
if is_authenticated: if is_authenticated:
context["voted"] = request.user.package_votes.filter( context["voted"] = db.query(
request.user.package_votes.filter(
PackageVote.PackageBaseID == pkgbase.ID PackageVote.PackageBaseID == pkgbase.ID
).exists()
).scalar() ).scalar()
else: else:
context["voted"] = False context["voted"] = False