From cdbfb740975436b9a4377402ae5c58f8be4aad92 Mon Sep 17 00:00:00 2001 From: Michiel Date: Fri, 8 Oct 2021 10:01:41 -0300 Subject: [PATCH] Ensure cache only rebuilds once (#750) * Make sure we only rebuild cache once * version * Get status_checkable_executor_job in on the fun * comment --- app/server/utils/executor.py | 2 ++ app/server/utils/metrics/metrics_cache.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/server/utils/executor.py b/app/server/utils/executor.py index 36f33814d..59a0ff4c4 100644 --- a/app/server/utils/executor.py +++ b/app/server/utils/executor.py @@ -54,6 +54,7 @@ def wrapper(*args, **kwargs): if g and g.get('active_organisation'): g.active_organisation = db.session.query(Organisation).filter(Organisation.id == g.active_organisation.id).first() db.session.merge(g.active_organisation) + db.session.merge(g.active_organisation.token) if g and g.get('user'): g.user = db.session.query(User).filter(User.id == g.user.id).first() db.session.merge(g.user) @@ -76,6 +77,7 @@ def wrapper(*args, **kwargs): if g and g.get('active_organisation'): g.active_organisation = db.session.query(Organisation).filter(Organisation.id == g.active_organisation.id).first() db.session.merge(g.active_organisation) + db.session.merge(g.active_organisation.token) if g and g.get('user'): g.user = db.session.query(User).filter(User.id == g.user.id).first() db.session.merge(g.user) diff --git a/app/server/utils/metrics/metrics_cache.py b/app/server/utils/metrics/metrics_cache.py index 75930a3f6..2e8a402ff 100644 --- a/app/server/utils/metrics/metrics_cache.py +++ b/app/server/utils/metrics/metrics_cache.py @@ -123,7 +123,11 @@ def _async_rebuild_metrics_cache(): from server.utils.metrics.metrics import calculate_transfer_stats calculate_transfer_stats(None, None, None, 'credit_transfer', 'all', False, 'day', 'ungrouped', None) calculate_transfer_stats(None, None, None, 'user', 'all', False, 'day', 'ungrouped', None) - _async_rebuild_metrics_cache.submit() + + if not g.get('is_rebuilding'): + _async_rebuild_metrics_cache.submit() + # ensure we don't rebuild cache several times at the end of a single call + g.is_rebuilding = True def _handle_combinatory_strategy(query, cache_result, strategy): return strategy_functions[strategy](query, cache_result)