From 119c34535ca30bdacab1d55820747a652258b6bf Mon Sep 17 00:00:00 2001 From: computergeek125 Date: Sun, 10 Apr 2022 17:46:07 -0500 Subject: [PATCH] Removed fn, reduced queries in login flow --- app/classes/shared/main_models.py | 9 +++------ app/classes/web/public_handler.py | 19 ++++++------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/app/classes/shared/main_models.py b/app/classes/shared/main_models.py index 8079f7d9..c110ca9a 100644 --- a/app/classes/shared/main_models.py +++ b/app/classes/shared/main_models.py @@ -10,7 +10,7 @@ Users = Users try: # pylint: disable=unused-import - from peewee import SqliteDatabase, fn + from peewee import SqliteDatabase from playhouse.shortcuts import model_to_dict except ModuleNotFoundError as err: @@ -20,11 +20,8 @@ logger = logging.getLogger(__name__) peewee_logger = logging.getLogger("peewee") peewee_logger.setLevel(logging.INFO) database = SqliteDatabase( - helper.db_path - # This is commented out after presenting issues when - # moving from SQLiteDatabase to SqliteQueueDatabase - # //TODO Enable tuning - # pragmas={"journal_mode": "wal", "cache_size": -1024 * 10} + helper.db_path, + pragmas={"journal_mode": "wal", "cache_size": -1024 * 10} ) diff --git a/app/classes/web/public_handler.py b/app/classes/web/public_handler.py index a91482ef..41083afc 100644 --- a/app/classes/web/public_handler.py +++ b/app/classes/web/public_handler.py @@ -1,9 +1,8 @@ import logging -from app.classes.models.users import Users +from app.classes.models.users import helper_users from app.classes.shared.authentication import authentication from app.classes.shared.helpers import helper -from app.classes.shared.main_models import fn from app.classes.web.base_handler import BaseHandler try: @@ -107,9 +106,8 @@ class PublicHandler(BaseHandler): entered_password = bleach.clean(self.get_argument("password")) # pylint: disable=no-member - user_data = Users.get_or_none( - fn.Lower(Users.username) == entered_username.lower() - ) + user_id = helper_users.get_user_id_by_name(entered_username.lower()) + user_data = helper_users.get_user_model(user_id) # if we don't have a user if not user_data: @@ -152,14 +150,9 @@ class PublicHandler(BaseHandler): ) # record this login - q = ( - Users.select() - .where(Users.username == entered_username.lower()) - .get() - ) - q.last_ip = self.get_remote_ip() - q.last_login = helper.get_time_as_string() - q.save() + user_data.last_ip = self.get_remote_ip() + user_data.last_login = helper.get_time_as_string() + user_data.save() # log this login self.controller.management.add_to_audit_log(