mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
[format] Using Black (#7769)
This commit is contained in:
@@ -22,7 +22,7 @@ from superset import tables_cache
|
||||
|
||||
def view_cache_key(*unused_args, **unused_kwargs) -> str:
|
||||
args_hash = hash(frozenset(request.args.items()))
|
||||
return 'view/{}/{}'.format(request.path, args_hash)
|
||||
return "view/{}/{}".format(request.path, args_hash)
|
||||
|
||||
|
||||
def memoized_func(key=view_cache_key, attribute_in_key=None):
|
||||
@@ -41,27 +41,32 @@ def memoized_func(key=view_cache_key, attribute_in_key=None):
|
||||
Key is a callable function that takes function arguments and
|
||||
returns the caching key.
|
||||
"""
|
||||
|
||||
def wrap(f):
|
||||
if tables_cache:
|
||||
|
||||
def wrapped_f(self, *args, **kwargs):
|
||||
if not kwargs.get('cache', True):
|
||||
if not kwargs.get("cache", True):
|
||||
return f(self, *args, **kwargs)
|
||||
|
||||
if attribute_in_key:
|
||||
cache_key = key(*args, **kwargs).format(
|
||||
getattr(self, attribute_in_key))
|
||||
getattr(self, attribute_in_key)
|
||||
)
|
||||
else:
|
||||
cache_key = key(*args, **kwargs)
|
||||
o = tables_cache.get(cache_key)
|
||||
if not kwargs.get('force') and o is not None:
|
||||
if not kwargs.get("force") and o is not None:
|
||||
return o
|
||||
o = f(self, *args, **kwargs)
|
||||
tables_cache.set(cache_key, o,
|
||||
timeout=kwargs.get('cache_timeout'))
|
||||
tables_cache.set(cache_key, o, timeout=kwargs.get("cache_timeout"))
|
||||
return o
|
||||
|
||||
else:
|
||||
# noop
|
||||
def wrapped_f(self, *args, **kwargs):
|
||||
return f(self, *args, **kwargs)
|
||||
|
||||
return wrapped_f
|
||||
|
||||
return wrap
|
||||
|
||||
Reference in New Issue
Block a user