forked from ScoDoc/DocScoDoc
DeferredSemCacheManager réentrant
This commit is contained in:
parent
a1f772b22e
commit
b698196a09
@ -231,29 +231,29 @@ def invalidate_formsemestre( # was inval_cache(formsemestre_id=None, pdfonly=Fa
|
|||||||
"""expire cache pour un semestre (ou tous si formsemestre_id non spécifié).
|
"""expire cache pour un semestre (ou tous si formsemestre_id non spécifié).
|
||||||
Si pdfonly, n'expire que les bulletins pdf cachés.
|
Si pdfonly, n'expire que les bulletins pdf cachés.
|
||||||
"""
|
"""
|
||||||
|
from app.models.formsemestre import FormSemestre
|
||||||
from app.scodoc import sco_cursus
|
from app.scodoc import sco_cursus
|
||||||
|
|
||||||
if getattr(g, "defer_cache_invalidation", False):
|
assert isinstance(formsemestre_id, int) or formsemestre_id is None
|
||||||
|
if getattr(g, "defer_cache_invalidation", 0) > 0:
|
||||||
g.sem_to_invalidate.add(formsemestre_id)
|
g.sem_to_invalidate.add(formsemestre_id)
|
||||||
return
|
return
|
||||||
log(f"inval_cache, formsemestre_id={formsemestre_id} pdfonly={pdfonly}")
|
|
||||||
if formsemestre_id is None:
|
if formsemestre_id is None:
|
||||||
# clear all caches
|
# clear all caches
|
||||||
log("----- invalidate_formsemestre: clearing all caches -----")
|
log(
|
||||||
|
f"----- invalidate_formsemestre: clearing all caches. pdfonly={pdfonly}-----"
|
||||||
|
)
|
||||||
formsemestre_ids = [
|
formsemestre_ids = [
|
||||||
x[0]
|
formsemestre.id
|
||||||
for x in ndb.SimpleQuery(
|
for formsemestre in FormSemestre.query.filter_by(dept_id=g.scodoc_dept_id)
|
||||||
"""SELECT id FROM notes_formsemestre s
|
|
||||||
WHERE s.dept_id=%(dept_id)s
|
|
||||||
""",
|
|
||||||
{"dept_id": g.scodoc_dept_id},
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
formsemestre_ids = [
|
formsemestre_ids = [
|
||||||
formsemestre_id
|
formsemestre_id
|
||||||
] + sco_cursus.list_formsemestre_utilisateurs_uecap(formsemestre_id)
|
] + sco_cursus.list_formsemestre_utilisateurs_uecap(formsemestre_id)
|
||||||
log(f"----- invalidate_formsemestre: clearing {formsemestre_ids} -----")
|
log(
|
||||||
|
f"----- invalidate_formsemestre: clearing {formsemestre_ids}. pdfonly={pdfonly} -----"
|
||||||
|
)
|
||||||
|
|
||||||
if not pdfonly:
|
if not pdfonly:
|
||||||
# Delete cached notes and evaluations
|
# Delete cached notes and evaluations
|
||||||
@ -289,17 +289,19 @@ class DeferredSemCacheManager:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
assert not hasattr(g, "defer_cache_invalidation")
|
if not hasattr(g, "defer_cache_invalidation"):
|
||||||
g.defer_cache_invalidation = True
|
g.defer_cache_invalidation = 0
|
||||||
g.sem_to_invalidate = set()
|
g.sem_to_invalidate = set()
|
||||||
|
g.defer_cache_invalidation += 1
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, exc_traceback):
|
def __exit__(self, exc_type, exc_value, exc_traceback):
|
||||||
assert g.defer_cache_invalidation
|
assert g.defer_cache_invalidation
|
||||||
g.defer_cache_invalidation = False
|
g.defer_cache_invalidation -= 1
|
||||||
while g.sem_to_invalidate:
|
if g.defer_cache_invalidation == 0:
|
||||||
formsemestre_id = g.sem_to_invalidate.pop()
|
while g.sem_to_invalidate:
|
||||||
invalidate_formsemestre(formsemestre_id)
|
formsemestre_id = g.sem_to_invalidate.pop()
|
||||||
|
invalidate_formsemestre(formsemestre_id)
|
||||||
|
|
||||||
|
|
||||||
# ---- Nouvelles classes ScoDoc 9.2
|
# ---- Nouvelles classes ScoDoc 9.2
|
||||||
|
Loading…
Reference in New Issue
Block a user