forked from ScoDoc/ScoDoc
code cleaning
This commit is contained in:
parent
bee7b74f17
commit
732a4c5ce5
@ -33,17 +33,12 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# API ScoDoc8 pour les caches:
|
# API pour les caches:
|
||||||
# sco_cache.NotesTableCache.get( formsemestre_id)
|
# sco_cache.MyCache.get( formsemestre_id)
|
||||||
# => sco_cache.NotesTableCache.get(formsemestre_id)
|
# => sco_cache.MyCache.get(formsemestre_id)
|
||||||
#
|
#
|
||||||
# sco_core.inval_cache(formsemestre_id=None, pdfonly=False, formsemestre_id_list=None)
|
# sco_cache.MyCache.delete(formsemestre_id)
|
||||||
# => deprecated, NotesTableCache.invalidate_formsemestre(formsemestre_id=None, pdfonly=False)
|
# sco_cache.MyCache.delete_many(formsemestre_id_list)
|
||||||
#
|
|
||||||
#
|
|
||||||
# Nouvelles fonctions:
|
|
||||||
# sco_cache.NotesTableCache.delete(formsemestre_id)
|
|
||||||
# sco_cache.NotesTableCache.delete_many(formsemestre_id_list)
|
|
||||||
#
|
#
|
||||||
# Bulletins PDF:
|
# Bulletins PDF:
|
||||||
# sco_cache.SemBulletinsPDFCache.get(formsemestre_id, version)
|
# sco_cache.SemBulletinsPDFCache.get(formsemestre_id, version)
|
||||||
@ -203,49 +198,6 @@ class SemInscriptionsCache(ScoDocCache):
|
|||||||
duration = 12 * 60 * 60 # ttl 12h
|
duration = 12 * 60 * 60 # ttl 12h
|
||||||
|
|
||||||
|
|
||||||
class NotesTableCache(ScoDocCache):
|
|
||||||
"""Cache pour les NotesTable
|
|
||||||
Clé: formsemestre_id
|
|
||||||
Valeur: NotesTable instance
|
|
||||||
"""
|
|
||||||
|
|
||||||
prefix = "NT"
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get(cls, formsemestre_id, compute=True):
|
|
||||||
"""Returns NotesTable for this formsemestre
|
|
||||||
Search in local cache (g.nt_cache) or global app cache (eg REDIS)
|
|
||||||
If not in cache:
|
|
||||||
If compute is True, build it and cache it
|
|
||||||
Else return None
|
|
||||||
"""
|
|
||||||
# try local cache (same request)
|
|
||||||
if not hasattr(g, "nt_cache"):
|
|
||||||
g.nt_cache = {}
|
|
||||||
else:
|
|
||||||
if formsemestre_id in g.nt_cache:
|
|
||||||
return g.nt_cache[formsemestre_id]
|
|
||||||
# try REDIS
|
|
||||||
key = cls._get_key(formsemestre_id)
|
|
||||||
nt = CACHE.get(key)
|
|
||||||
if nt:
|
|
||||||
g.nt_cache[formsemestre_id] = nt # cache locally (same request)
|
|
||||||
return nt
|
|
||||||
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) # 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
|
|
||||||
return nt
|
|
||||||
|
|
||||||
|
|
||||||
def invalidate_formsemestre( # was inval_cache(formsemestre_id=None, pdfonly=False)
|
def invalidate_formsemestre( # was inval_cache(formsemestre_id=None, pdfonly=False)
|
||||||
formsemestre_id=None, pdfonly=False
|
formsemestre_id=None, pdfonly=False
|
||||||
):
|
):
|
||||||
@ -278,22 +230,24 @@ def invalidate_formsemestre( # was inval_cache(formsemestre_id=None, pdfonly=Fa
|
|||||||
|
|
||||||
if not pdfonly:
|
if not pdfonly:
|
||||||
# Delete cached notes and evaluations
|
# Delete cached notes and evaluations
|
||||||
NotesTableCache.delete_many(formsemestre_ids)
|
|
||||||
if formsemestre_id:
|
if formsemestre_id:
|
||||||
for fid in formsemestre_ids:
|
for fid in formsemestre_ids:
|
||||||
EvaluationCache.invalidate_sem(fid)
|
EvaluationCache.invalidate_sem(fid)
|
||||||
if hasattr(g, "nt_cache") and fid in g.nt_cache:
|
if (
|
||||||
del g.nt_cache[fid]
|
hasattr(g, "formsemestre_results_cache")
|
||||||
|
and fid in g.formsemestre_results_cache
|
||||||
|
):
|
||||||
|
del g.formsemestre_results_cache[fid]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# optimization when we invalidate all evaluations:
|
# optimization when we invalidate all evaluations:
|
||||||
EvaluationCache.invalidate_all_sems()
|
EvaluationCache.invalidate_all_sems()
|
||||||
if hasattr(g, "nt_cache"):
|
if hasattr(g, "formsemestre_results_cache"):
|
||||||
del g.nt_cache
|
del g.formsemestre_results_cache
|
||||||
SemInscriptionsCache.delete_many(formsemestre_ids)
|
SemInscriptionsCache.delete_many(formsemestre_ids)
|
||||||
|
ResultatsSemestreCache.delete_many(formsemestre_ids)
|
||||||
|
ValidationsSemestreCache.delete_many(formsemestre_ids)
|
||||||
SemBulletinsPDFCache.invalidate_sems(formsemestre_ids)
|
SemBulletinsPDFCache.invalidate_sems(formsemestre_ids)
|
||||||
ResultatsSemestreCache.delete_many(formsemestre_ids)
|
|
||||||
ValidationsSemestreCache.delete_many(formsemestre_ids)
|
|
||||||
|
|
||||||
|
|
||||||
class DefferedSemCacheManager:
|
class DefferedSemCacheManager:
|
||||||
|
Loading…
Reference in New Issue
Block a user