fix: optimize email validation in forms
Refactored the email lookup logic in the EmailForm class to fetch all users once and then search the list in Python, rather than making a database call for each email validation. This change reduces database load and potentially speeds up form processing by avoiding multiple queries. It's particularly beneficial when dealing with a large number of users, ensuring scalability and improved performance of the application. The new approach retrieves the list of users upfront and iterates over it to find a match, falling back to `None` if no user with the specified email exists. This method is more efficient and aligns with best practices for handling database interactions in a web application.
This commit is contained in:
parent
aa4065e219
commit
2c976a9c03
1 changed files with 3 additions and 1 deletions
4
app.py
4
app.py
|
@ -198,7 +198,9 @@ class EmailForm(FlaskForm):
|
|||
users = User(planka)
|
||||
|
||||
try:
|
||||
user = users.get(email=field.data)
|
||||
user_list = users.get()
|
||||
|
||||
user = next((u for u in user_list if u["email"] == field.data), None)
|
||||
|
||||
if user:
|
||||
raise ValidationError(
|
||||
|
|
Loading…
Reference in a new issue