Performance boost: NotesTableCache was not always caching locally

This commit is contained in:
Emmanuel Viennet 2021-08-31 19:28:57 +02:00
parent 3ac4623421
commit 2fbce89edd
1 changed files with 6 additions and 3 deletions

View File

@ -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