diff --git a/app/scodoc/sco_cache.py b/app/scodoc/sco_cache.py index 0798a37d24..65307d7e96 100644 --- a/app/scodoc/sco_cache.py +++ b/app/scodoc/sco_cache.py @@ -231,29 +231,29 @@ def invalidate_formsemestre( # was inval_cache(formsemestre_id=None, pdfonly=Fa """expire cache pour un semestre (ou tous si formsemestre_id non spécifié). Si pdfonly, n'expire que les bulletins pdf cachés. """ + from app.models.formsemestre import FormSemestre from app.scodoc import sco_cursus - if getattr(g, "defer_cache_invalidation", False): + assert isinstance(formsemestre_id, int) or formsemestre_id is None + if getattr(g, "defer_cache_invalidation", 0) > 0: g.sem_to_invalidate.add(formsemestre_id) return - log(f"inval_cache, formsemestre_id={formsemestre_id} pdfonly={pdfonly}") if formsemestre_id is None: # clear all caches - log("----- invalidate_formsemestre: clearing all caches -----") + log( + f"----- invalidate_formsemestre: clearing all caches. pdfonly={pdfonly}-----" + ) formsemestre_ids = [ - x[0] - for x in ndb.SimpleQuery( - """SELECT id FROM notes_formsemestre s - WHERE s.dept_id=%(dept_id)s - """, - {"dept_id": g.scodoc_dept_id}, - ) + formsemestre.id + for formsemestre in FormSemestre.query.filter_by(dept_id=g.scodoc_dept_id) ] else: formsemestre_ids = [ formsemestre_id ] + sco_cursus.list_formsemestre_utilisateurs_uecap(formsemestre_id) - log(f"----- invalidate_formsemestre: clearing {formsemestre_ids} -----") + log( + f"----- invalidate_formsemestre: clearing {formsemestre_ids}. pdfonly={pdfonly} -----" + ) if not pdfonly: # Delete cached notes and evaluations @@ -289,17 +289,19 @@ class DeferredSemCacheManager: """ def __enter__(self): - assert not hasattr(g, "defer_cache_invalidation") - g.defer_cache_invalidation = True - g.sem_to_invalidate = set() + if not hasattr(g, "defer_cache_invalidation"): + g.defer_cache_invalidation = 0 + g.sem_to_invalidate = set() + g.defer_cache_invalidation += 1 return True def __exit__(self, exc_type, exc_value, exc_traceback): assert g.defer_cache_invalidation - g.defer_cache_invalidation = False - while g.sem_to_invalidate: - formsemestre_id = g.sem_to_invalidate.pop() - invalidate_formsemestre(formsemestre_id) + g.defer_cache_invalidation -= 1 + if g.defer_cache_invalidation == 0: + while g.sem_to_invalidate: + formsemestre_id = g.sem_to_invalidate.pop() + invalidate_formsemestre(formsemestre_id) # ---- Nouvelles classes ScoDoc 9.2