From cac6201696ee92db5440ef8d6eace20b0b98cf6e Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 21 Feb 2023 01:07:21 +0100 Subject: [PATCH] Cache table recap: combinaisons evals/jury --- app/scodoc/sco_cache.py | 20 ++++++++++++++++++++ app/scodoc/sco_recapcomplet.py | 16 ++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/scodoc/sco_cache.py b/app/scodoc/sco_cache.py index c197079d..23b18a6d 100644 --- a/app/scodoc/sco_cache.py +++ b/app/scodoc/sco_cache.py @@ -229,6 +229,26 @@ class TableRecapWithEvalsCache(ScoDocCache): duration = 12 * 60 * 60 # ttl 12h +class TableJuryCache(ScoDocCache): + """Cache table recap (pour TableRecap) + Clé: formsemestre_id + Valeur: le html (
...
) + """ + + prefix = "RECAPJURY" + duration = 12 * 60 * 60 # ttl 12h + + +class TableJuryWithEvalsCache(ScoDocCache): + """Cache table recap (pour TableRecap) + Clé: formsemestre_id + Valeur: le html (
...
) + """ + + prefix = "RECAPJURYWITHEVALS" + duration = 12 * 60 * 60 # ttl 12h + + def invalidate_formsemestre( # was inval_cache(formsemestre_id=None, pdfonly=False) formsemestre_id=None, pdfonly=False ): diff --git a/app/scodoc/sco_recapcomplet.py b/app/scodoc/sco_recapcomplet.py index e91f3681..011a5708 100644 --- a/app/scodoc/sco_recapcomplet.py +++ b/app/scodoc/sco_recapcomplet.py @@ -449,11 +449,14 @@ def gen_formsemestre_recapcomplet_html_table( """ table = None table_html = None + cache_class = { + (True, True): sco_cache.TableJuryWithEvalsCache, + (True, False): sco_cache.TableJuryCache, + (False, True): sco_cache.TableRecapWithEvalsCache, + (False, False): sco_cache.TableRecapCache, + }[(bool(mode_jury), bool(include_evaluations))] if not selected_etudid: - if include_evaluations: - table_html = sco_cache.TableRecapWithEvalsCache.get(formsemestre.id) - else: - table_html = sco_cache.TableRecapCache.get(formsemestre.id) + table_html = cache_class.get(formsemestre.id) if table_html is None: table = _gen_formsemestre_recapcomplet_table( formsemestre, @@ -464,10 +467,7 @@ def gen_formsemestre_recapcomplet_html_table( selected_etudid=selected_etudid, ) table_html = table.html() - if include_evaluations: - sco_cache.TableRecapWithEvalsCache.set(formsemestre.id, table_html) - else: - sco_cache.TableRecapCache.set(formsemestre.id, table_html) + cache_class.set(formsemestre.id, table_html) return table_html, table