Better cache configuration

pull/78/head
Konstantin Gründger 2020-11-25 11:14:36 +01:00
rodzic f8b3457997
commit 3193446131
2 zmienionych plików z 8 dodań i 3 usunięć

Wyświetl plik

@ -10,14 +10,14 @@ from app.main import bp
from app.main.matplotlib_service import create_range_figure from app.main.matplotlib_service import create_range_figure
@cache.cached(key_prefix="countries_in_receivers") @cache.cached()
def get_countries_in_receivers(): def get_countries_in_receivers():
query = db.session.query(Country.iso2).filter(Country.gid == Receiver.country_id).order_by(Country.iso2).distinct(Country.iso2) query = db.session.query(Country.iso2).filter(Country.gid == Receiver.country_id).order_by(Country.iso2).distinct(Country.iso2)
return [{"iso2": country[0]} for country in query.all()] return [{"iso2": country[0]} for country in query.all()]
@cache.cached(key_prefix="countries_in_takeoff_landings") @cache.cached()
def get_used_countries(): def get_used_countries():
query = db.session.query(Country.iso2).filter(Country.gid == TakeoffLanding.country_id).order_by(Country.iso2).distinct(Country.iso2) query = db.session.query(Country.iso2).filter(Country.gid == TakeoffLanding.country_id).order_by(Country.iso2).distinct(Country.iso2)
return [{"iso2": country[0]} for country in query.all()] return [{"iso2": country[0]} for country in query.all()]
@ -44,6 +44,7 @@ def get_dates_for_airport(sel_airport):
@bp.route("/") @bp.route("/")
@bp.route("/index.html") @bp.route("/index.html")
@cache.cached()
def index(): def index():
today_beginning = datetime.combine(date.today(), time()) today_beginning = datetime.combine(date.today(), time())
@ -67,6 +68,7 @@ def index():
@bp.route("/senders.html", methods=["GET", "POST"]) @bp.route("/senders.html", methods=["GET", "POST"])
@cache.cached()
def senders(): def senders():
senders = db.session.query(Sender) \ senders = db.session.query(Sender) \
.options(db.joinedload(Sender.infos)) \ .options(db.joinedload(Sender.infos)) \
@ -98,6 +100,7 @@ def range_view():
@bp.route("/receivers.html") @bp.route("/receivers.html")
@cache.cached()
def receivers(): def receivers():
sel_country = request.args.get("country") sel_country = request.args.get("country")
@ -214,6 +217,7 @@ def download_flight():
@bp.route("/sender_ranking.html") @bp.route("/sender_ranking.html")
@cache.cached()
def sender_ranking(): def sender_ranking():
sender_statistics = db.session.query(SenderStatistic) \ sender_statistics = db.session.query(SenderStatistic) \
.filter(db.and_(SenderStatistic.date == date.today(), SenderStatistic.is_trustworthy == db.true())) \ .filter(db.and_(SenderStatistic.date == date.today(), SenderStatistic.is_trustworthy == db.true())) \
@ -227,6 +231,7 @@ def sender_ranking():
@bp.route("/receiver_ranking.html") @bp.route("/receiver_ranking.html")
@cache.cached()
def receiver_ranking(): def receiver_ranking():
receiver_statistics = db.session.query(ReceiverStatistic) \ receiver_statistics = db.session.query(ReceiverStatistic) \
.filter(db.and_(ReceiverStatistic.date == date.today(), ReceiverStatistic.is_trustworthy == db.true())) \ .filter(db.and_(ReceiverStatistic.date == date.today(), ReceiverStatistic.is_trustworthy == db.true())) \

Wyświetl plik

@ -5,7 +5,7 @@ class BaseConfig:
SECRET_KEY = "i-like-ogn" SECRET_KEY = "i-like-ogn"
# Flask-Cache stuff # Flask-Cache stuff
CACHE_TYPE = "simple" CACHE_TYPE = "redis"
CACHE_DEFAULT_TIMEOUT = 300 CACHE_DEFAULT_TIMEOUT = 300
# Redis stuff # Redis stuff