mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
perf(aurweb/pkgbase): only relevant queries when logged in
Don't query for notify, requests and vote information when the user is not logged in as this information is not shown.
This commit is contained in:
parent
d393ed2352
commit
b65d6c5e3a
1 changed files with 23 additions and 9 deletions
|
@ -26,6 +26,8 @@ def make_context(
|
|||
if not context:
|
||||
context = _make_context(request, pkgbase.Name)
|
||||
|
||||
is_authenticated = request.user.is_authenticated()
|
||||
|
||||
# Per page and offset.
|
||||
offset, per_page = util.sanitize_params(
|
||||
request.query_params.get("O", defaults.O),
|
||||
|
@ -42,8 +44,11 @@ def make_context(
|
|||
PackageComaintainer.Priority.asc()
|
||||
).all()
|
||||
]
|
||||
if is_authenticated:
|
||||
context["unflaggers"] = context["comaintainers"].copy()
|
||||
context["unflaggers"].extend([pkgbase.Maintainer, pkgbase.Flagger])
|
||||
else:
|
||||
context["unflaggers"] = []
|
||||
|
||||
context["packages_count"] = pkgbase.packages.count()
|
||||
context["keywords"] = pkgbase.keywords
|
||||
|
@ -60,17 +65,26 @@ def make_context(
|
|||
).order_by(PackageComment.CommentTS.desc())
|
||||
|
||||
context["is_maintainer"] = bool(request.user == pkgbase.Maintainer)
|
||||
if is_authenticated:
|
||||
context["notified"] = request.user.notified(pkgbase)
|
||||
else:
|
||||
context["notified"] = False
|
||||
|
||||
context["out_of_date"] = bool(pkgbase.OutOfDateTS)
|
||||
|
||||
if is_authenticated:
|
||||
context["voted"] = request.user.package_votes.filter(
|
||||
PackageVote.PackageBaseID == pkgbase.ID
|
||||
).scalar()
|
||||
else:
|
||||
context["voted"] = False
|
||||
|
||||
if is_authenticated:
|
||||
context["requests"] = pkgbase.requests.filter(
|
||||
and_(PackageRequest.Status == PENDING_ID, PackageRequest.ClosedTS.is_(None))
|
||||
).count()
|
||||
else:
|
||||
context["requests"] = []
|
||||
|
||||
context["popularity"] = popularity(pkgbase, time.utcnow())
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue