From 59370e1520cc5ebb6a6e95e0f831f76e8d557bba Mon Sep 17 00:00:00 2001 From: mkangia Date: Tue, 5 Nov 2024 01:12:49 +0530 Subject: [PATCH] avoid sync conflicts --- hq_superset/hq_domain.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hq_superset/hq_domain.py b/hq_superset/hq_domain.py index 1a08b96..9b90dba 100644 --- a/hq_superset/hq_domain.py +++ b/hq_superset/hq_domain.py @@ -3,6 +3,7 @@ import superset from flask import current_app, flash, g, redirect, request, session, url_for from superset.config import USER_DOMAIN_ROLE_EXPIRY +from superset.extensions import cache_manager from hq_superset.const import ( SESSION_DOMAIN_ROLE_LAST_SYNCED_AT, @@ -84,7 +85,15 @@ def sync_user_domain_role(): ): return if _domain_role_expired(): - return _sync_domain_role() + cache_key = f"{g.user.id}_{g.hq_domain}_sync_domain_role" + # only sync if another sync not in progress + if not cache_manager.cache.get(cache_key): + cache_manager.cache.set(cache_key, True) + + sync_domain_role_response = _sync_domain_role() + + cache_manager.cache.delete(cache_key) + return sync_domain_role_response def _domain_role_expired():