From 2fbce89edd9fb6397dc755397f518eaa343b1684 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 31 Aug 2021 19:28:57 +0200 Subject: [PATCH] Performance boost: NotesTableCache was not always caching locally --- app/scodoc/sco_cache.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/scodoc/sco_cache.py b/app/scodoc/sco_cache.py index 4ccfb7481..94f954095 100644 --- a/app/scodoc/sco_cache.py +++ b/app/scodoc/sco_cache.py @@ -225,15 +225,18 @@ class NotesTableCache(ScoDocCache): # try REDIS key = cls._get_key(formsemestre_id) nt = CACHE.get(key) - if nt or not compute: + if nt: + g.nt_cache[formsemestre_id] = nt # cache locally (same request) return nt - # Recompute asked table: + if not compute: + return None + # Recompute requested table: from app.scodoc import notes_table t0 = time.time() nt = notes_table.NotesTable(formsemestre_id) t1 = time.time() - _ = cls.set(formsemestre_id, nt) + _ = cls.set(formsemestre_id, nt) # cache in REDIS t2 = time.time() log(f"cached formsemestre_id={formsemestre_id} ({(t1-t0):g}s +{(t2-t1):g}s)") g.nt_cache[formsemestre_id] = nt