From 75f8c3b5009f771aabc6ab06c7b91e71d7aef5cf Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 22 Apr 2022 11:20:06 +0200 Subject: [PATCH] =?UTF-8?q?Export=20Apo:=20cache=20inscrits=20=C3=A9tapes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_portal_apogee.py | 18 +++++++++++++++++- sco_version.py | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/scodoc/sco_portal_apogee.py b/app/scodoc/sco_portal_apogee.py index 836be2ed..e4684e68 100644 --- a/app/scodoc/sco_portal_apogee.py +++ b/app/scodoc/sco_portal_apogee.py @@ -37,12 +37,20 @@ import xml.dom.minidom import app.scodoc.sco_utils as scu from app import log +from app.scodoc import sco_cache from app.scodoc.sco_exceptions import ScoValueError from app.scodoc import sco_preferences SCO_CACHE_ETAPE_FILENAME = os.path.join(scu.SCO_TMP_DIR, "last_etapes.xml") +class ApoInscritsEtapeCache(sco_cache.ScoDocCache): + """Cache liste des inscrits à une étape Apogée""" + + timeout = 10 * 60 # 10 minutes + prefix = "APOINSCRETAP" + + def has_portal(): "True if we are connected to a portal" return get_portal_url() @@ -139,14 +147,20 @@ get_maquette_url = _PI.get_maquette_url get_portal_api_version = _PI.get_portal_api_version -def get_inscrits_etape(code_etape, anneeapogee=None, ntrials=2): +def get_inscrits_etape(code_etape, anneeapogee=None, ntrials=2, use_cache=True): """Liste des inscrits à une étape Apogée Result = list of dicts ntrials: try several time the same request, useful for some bad web services + use_cache: use (redis) cache """ log("get_inscrits_etape: code=%s anneeapogee=%s" % (code_etape, anneeapogee)) if anneeapogee is None: anneeapogee = str(time.localtime()[0]) + if use_cache: + obj = ApoInscritsEtapeCache.get((code_etape, anneeapogee)) + if obj: + log("get_inscrits_etape: using cached data") + return obj etud_url = get_etud_url() api_ver = get_portal_api_version() @@ -189,6 +203,8 @@ def get_inscrits_etape(code_etape, anneeapogee=None, ntrials=2): return False # ??? pas d'annee d'inscription dans la réponse etuds = [e for e in etuds if check_inscription(e)] + if use_cache and etuds: + ApoInscritsEtapeCache.set((code_etape, anneeapogee), etuds) return etuds diff --git a/sco_version.py b/sco_version.py index 06ddcfb8..ea996181 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.2.8" +SCOVERSION = "9.2.9" SCONAME = "ScoDoc"