From ac882e9ccd0bec055f43c3633c1865defc7ac29c Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 19 May 2024 22:57:21 +0200 Subject: [PATCH] Fix: cache poids evals (invalidation manquante) --- app/comp/df_cache.py | 25 +++++++++++++++++++++++++ app/scodoc/sco_cache.py | 5 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/comp/df_cache.py b/app/comp/df_cache.py index fb4c6cade..59dded343 100644 --- a/app/comp/df_cache.py +++ b/app/comp/df_cache.py @@ -27,6 +27,7 @@ """caches pour tables APC """ +from flask import g from app.scodoc import sco_cache @@ -47,3 +48,27 @@ class EvaluationsPoidsCache(sco_cache.ScoDocCache): """ prefix = "EPC" + + @classmethod + def invalidate_all(cls): + "delete all cached evaluations poids (in current dept)" + from app.models.formsemestre import FormSemestre + from app.models.moduleimpls import ModuleImpl + + moduleimpl_ids = [ + mi.id + for mi in ModuleImpl.query.join(FormSemestre).filter_by( + dept_id=g.scodoc_dept_id + ) + ] + cls.delete_many(moduleimpl_ids) + + @classmethod + def invalidate_sem(cls, formsemestre_id): + "delete cached evaluations poids for this formsemestre from cache" + from app.models.moduleimpls import ModuleImpl + + moduleimpl_ids = [ + mi.id for mi in ModuleImpl.query.filter_by(formsemestre_id=formsemestre_id) + ] + cls.delete_many(moduleimpl_ids) diff --git a/app/scodoc/sco_cache.py b/app/scodoc/sco_cache.py index 677dae6c9..102e4e433 100644 --- a/app/scodoc/sco_cache.py +++ b/app/scodoc/sco_cache.py @@ -274,6 +274,7 @@ def invalidate_formsemestre( # was inval_cache(formsemestre_id=None, pdfonly=Fa """expire cache pour un semestre (ou tous ceux du département si formsemestre_id non spécifié). Si pdfonly, n'expire que les bulletins pdf cachés. """ + from app.comp import df_cache from app.models.formsemestre import FormSemestre from app.scodoc import sco_cursus @@ -315,12 +316,14 @@ def invalidate_formsemestre( # was inval_cache(formsemestre_id=None, pdfonly=Fa and fid in g.formsemestre_results_cache ): del g.formsemestre_results_cache[fid] - + df_cache.EvaluationsPoidsCache.invalidate_sem(formsemestre_id) else: # optimization when we invalidate all evaluations: EvaluationCache.invalidate_all_sems() + df_cache.EvaluationsPoidsCache.invalidate_all() if hasattr(g, "formsemestre_results_cache"): del g.formsemestre_results_cache + SemInscriptionsCache.delete_many(formsemestre_ids) ResultatsSemestreCache.delete_many(formsemestre_ids) ValidationsSemestreCache.delete_many(formsemestre_ids)