1
0
forked from ScoDoc/ScoDoc

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

View File

@ -225,15 +225,18 @@ class NotesTableCache(ScoDocCache):
# try REDIS # try REDIS
key = cls._get_key(formsemestre_id) key = cls._get_key(formsemestre_id)
nt = CACHE.get(key) nt = CACHE.get(key)
if nt or not compute: if nt:
g.nt_cache[formsemestre_id] = nt # cache locally (same request)
return nt return nt
# Recompute asked table: if not compute:
return None
# Recompute requested table:
from app.scodoc import notes_table from app.scodoc import notes_table
t0 = time.time() t0 = time.time()
nt = notes_table.NotesTable(formsemestre_id) nt = notes_table.NotesTable(formsemestre_id)
t1 = time.time() t1 = time.time()
_ = cls.set(formsemestre_id, nt) _ = cls.set(formsemestre_id, nt) # cache in REDIS
t2 = time.time() t2 = time.time()
log(f"cached formsemestre_id={formsemestre_id} ({(t1-t0):g}s +{(t2-t1):g}s)") log(f"cached formsemestre_id={formsemestre_id} ({(t1-t0):g}s +{(t2-t1):g}s)")
g.nt_cache[formsemestre_id] = nt g.nt_cache[formsemestre_id] = nt