mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
perf(captcha): simplify count() query for user ids
Using .count() isn't great as it runs a count query on a subquery which selects all fields in the Users table. This rewrites it into a simple SELECT count(ID) from USers query.
This commit is contained in:
parent
97cc6196eb
commit
edc1ab949a
1 changed files with 3 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from jinja2 import pass_context
|
from jinja2 import pass_context
|
||||||
|
from sqlalchemy import func
|
||||||
|
|
||||||
from aurweb.db import query
|
from aurweb.db import query
|
||||||
from aurweb.models import User
|
from aurweb.models import User
|
||||||
|
@ -11,7 +12,8 @@ from aurweb.templates import register_filter
|
||||||
|
|
||||||
def get_captcha_salts():
|
def get_captcha_salts():
|
||||||
"""Produce salts based on the current user count."""
|
"""Produce salts based on the current user count."""
|
||||||
count = query(User).count()
|
count = query(func.count(User.ID)).scalar()
|
||||||
|
|
||||||
salts = []
|
salts = []
|
||||||
for i in range(0, 6):
|
for i in range(0, 6):
|
||||||
salts.append(f"aurweb-{count - i}")
|
salts.append(f"aurweb-{count - i}")
|
||||||
|
|
Loading…
Add table
Reference in a new issue