Skip to content

Commit

Permalink
Ensure cache only rebuilds once (#750)
Browse files Browse the repository at this point in the history
* Make sure we only rebuild cache once

* version

* Get status_checkable_executor_job in on the fun

* comment
  • Loading branch information
michielderoos committed Oct 8, 2021
1 parent 7871c61 commit cdbfb74
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/server/utils/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion app/server/utils/metrics/metrics_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cdbfb74

Please sign in to comment.