From 970e1ca65e99cbf1260288addcbfe9dfccf089fe Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Fri, 29 May 2020 00:55:40 -0400 Subject: [PATCH] 1402 sqlalchemy optimization exploration (#1450) * Experimental ideas to make SQLAlchemy queries faster by switching them to SQLAlchemy Core * Starts work on #1402 --- CTFd/utils/__init__.py | 4 +++- CTFd/utils/config/pages.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CTFd/utils/__init__.py b/CTFd/utils/__init__.py index e3a3e696..f4dce6cc 100644 --- a/CTFd/utils/__init__.py +++ b/CTFd/utils/__init__.py @@ -23,7 +23,9 @@ def get_app_config(key, default=None): @cache.memoize() def _get_config(key): - config = Configs.query.filter_by(key=key).first() + config = db.session.execute( + Configs.__table__.select().where(Configs.key == key) + ).fetchone() if config and config.value: value = config.value if value and value.isdigit(): diff --git a/CTFd/utils/config/pages.py b/CTFd/utils/config/pages.py index c5811e99..cb9cb535 100644 --- a/CTFd/utils/config/pages.py +++ b/CTFd/utils/config/pages.py @@ -1,5 +1,5 @@ from CTFd.cache import cache -from CTFd.models import Pages +from CTFd.models import db, Pages @cache.memoize() @@ -12,4 +12,8 @@ def get_pages(): @cache.memoize() def get_page(route): - return Pages.query.filter(Pages.route == route, Pages.draft.isnot(True)).first() + return db.session.execute( + Pages.__table__.select() + .where(Pages.route == route) + .where(Pages.draft.isnot(True)) + ).fetchone()