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"