Removed fn, reduced queries in login flow

This commit is contained in:
computergeek125 2022-04-10 17:46:07 -05:00
parent d78d51d091
commit 119c34535c
2 changed files with 9 additions and 19 deletions

View File

@ -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}
)

View File

@ -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(