Skip to content

Commit

Permalink
avoid sync conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mkangia committed Nov 4, 2024
1 parent 96411fc commit 59370e1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hq_superset/hq_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 59370e1

Please sign in to comment.