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: try:
# pylint: disable=unused-import # pylint: disable=unused-import
from peewee import SqliteDatabase, fn from peewee import SqliteDatabase
from playhouse.shortcuts import model_to_dict from playhouse.shortcuts import model_to_dict
except ModuleNotFoundError as err: except ModuleNotFoundError as err:
@ -20,11 +20,8 @@ logger = logging.getLogger(__name__)
peewee_logger = logging.getLogger("peewee") peewee_logger = logging.getLogger("peewee")
peewee_logger.setLevel(logging.INFO) peewee_logger.setLevel(logging.INFO)
database = SqliteDatabase( database = SqliteDatabase(
helper.db_path helper.db_path,
# This is commented out after presenting issues when pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
# moving from SQLiteDatabase to SqliteQueueDatabase
# //TODO Enable tuning
# pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
) )

View File

@ -1,9 +1,8 @@
import logging 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.authentication import authentication
from app.classes.shared.helpers import helper from app.classes.shared.helpers import helper
from app.classes.shared.main_models import fn
from app.classes.web.base_handler import BaseHandler from app.classes.web.base_handler import BaseHandler
try: try:
@ -107,9 +106,8 @@ class PublicHandler(BaseHandler):
entered_password = bleach.clean(self.get_argument("password")) entered_password = bleach.clean(self.get_argument("password"))
# pylint: disable=no-member # pylint: disable=no-member
user_data = Users.get_or_none( user_id = helper_users.get_user_id_by_name(entered_username.lower())
fn.Lower(Users.username) == entered_username.lower() user_data = helper_users.get_user_model(user_id)
)
# if we don't have a user # if we don't have a user
if not user_data: if not user_data:
@ -152,14 +150,9 @@ class PublicHandler(BaseHandler):
) )
# record this login # record this login
q = ( user_data.last_ip = self.get_remote_ip()
Users.select() user_data.last_login = helper.get_time_as_string()
.where(Users.username == entered_username.lower()) user_data.save()
.get()
)
q.last_ip = self.get_remote_ip()
q.last_login = helper.get_time_as_string()
q.save()
# log this login # log this login
self.controller.management.add_to_audit_log( self.controller.management.add_to_audit_log(