From 7a6d25ac434435d604cf356777b0ec2edc671b50 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 12 Jun 2016 22:30:05 +0200 Subject: [PATCH] server/tags: cache default tag category --- server/szurubooru/func/tag_categories.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/szurubooru/func/tag_categories.py b/server/szurubooru/func/tag_categories.py index 5e91c48..64e6bec 100644 --- a/server/szurubooru/func/tag_categories.py +++ b/server/szurubooru/func/tag_categories.py @@ -1,6 +1,6 @@ import re from szurubooru import config, db, errors -from szurubooru.func import util, snapshots +from szurubooru.func import util, snapshots, cache class TagCategoryNotFoundError(errors.NotFoundError): pass class TagCategoryAlreadyExistsError(errors.ValidationError): pass @@ -77,6 +77,9 @@ def get_all_categories(): return db.session.query(db.TagCategory).all() def try_get_default_category(): + key = 'default-tag-category' + if cache.has(key): + return cache.get(key) category = db.session \ .query(db.TagCategory) \ .filter(db.TagCategory.default) \ @@ -88,6 +91,7 @@ def try_get_default_category(): .query(db.TagCategory) \ .order_by(db.TagCategory.tag_category_id.asc()) \ .first() + cache.put(key, category) return category def get_default_category():