diff --git a/superset/assets/src/SqlLab/components/SqlEditorLeftBar.jsx b/superset/assets/src/SqlLab/components/SqlEditorLeftBar.jsx
index 97e392c7d2efe..e6e7f5dd26f86 100644
--- a/superset/assets/src/SqlLab/components/SqlEditorLeftBar.jsx
+++ b/superset/assets/src/SqlLab/components/SqlEditorLeftBar.jsx
@@ -40,8 +40,7 @@ class SqlEditorLeftBar extends React.PureComponent {
}
onDatabaseChange(db, force) {
const val = db ? db.value : null;
- this.setState({ schemaOptions: [] });
- this.setState({ tableOptions: [] });
+ this.setState({ schemaOptions: [], tableOptions: [] });
this.props.actions.queryEditorSetSchema(this.props.queryEditor, null);
this.props.actions.queryEditorSetDb(this.props.queryEditor, val);
if (db) {
@@ -195,7 +194,7 @@ class SqlEditorLeftBar extends React.PureComponent {
@@ -244,7 +243,7 @@ class SqlEditorLeftBar extends React.PureComponent {
diff --git a/superset/cache_util.py b/superset/cache_util.py
index 12bed2b18070f..38516a6a50f77 100644
--- a/superset/cache_util.py
+++ b/superset/cache_util.py
@@ -9,25 +9,17 @@ def view_cache_key(*unused_args, **unused_kwargs):
return 'view/{}/{}'.format(request.path, args_hash)
-def default_timeout(*unused_args, **unused_kwargs):
- return 5 * 60
-
-
-def default_enable_cache(*unused_args, **unused_kwargs):
- return True
+def memoized_func(key=view_cache_key, use_tables_cache=False):
+ """Use this decorator to cache functions that have predefined first arg.
+ enable_cache is treated as True by default,
+ except enable_cache = False is passed to the decorated function.
-def memoized_func(timeout=default_timeout,
- key=view_cache_key,
- enable_cache=default_enable_cache,
- use_tables_cache=False):
- """Use this decorator to cache functions that have predefined first arg.
+ force is treated as False by default,
+ except force = True is passed to the decorated function.
- If enable_cache() is False,
- the function will never be cached.
- If enable_cache() is True,
- cache is adopted and will timeout in timeout() seconds.
- If force is True, cache will be refreshed.
+ timeout of cache is set to 600 seconds by default,
+ except cache_timeout = {timeout in seconds} is passed to the decorated function.
memoized_func uses simple_cache and stored the data in memory.
Key is a callable function that takes function arguments and
@@ -42,15 +34,16 @@ def wrap(f):
if selected_cache:
def wrapped_f(cls, *args, **kwargs):
- if not enable_cache(*args, **kwargs):
+ if not kwargs.get('enable_cache', True):
return f(cls, *args, **kwargs)
cache_key = key(*args, **kwargs)
o = selected_cache.get(cache_key)
- if not kwargs['force'] and o is not None:
+ if not kwargs.get('force') and o is not None:
return o
o = f(cls, *args, **kwargs)
- selected_cache.set(cache_key, o, timeout=timeout(*args, **kwargs))
+ selected_cache.set(cache_key, o,
+ timeout=kwargs.get('cache_timeout', 600))
return o
else:
# noop
diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index 0f3a4c8a0864c..20d57d6976612 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -228,7 +228,6 @@ def convert_dttm(cls, target_type, dttm):
@classmethod
@cache_util.memoized_func(
- timeout=600,
key=lambda *args, **kwargs: 'db:{}:{}'.format(args[0].id, args[1]),
use_tables_cache=True)
def fetch_result_sets(cls, db, datasource_type, force=False):
@@ -295,8 +294,6 @@ def patch(cls):
@classmethod
@cache_util.memoized_func(
- enable_cache=lambda *args, **kwargs: kwargs.get('enable_cache', False),
- timeout=lambda *args, **kwargs: kwargs.get('cache_timeout'),
key=lambda *args, **kwargs: 'db:{}:schema_list'.format(kwargs.get('db_id')))
def get_schema_names(cls, inspector, db_id,
enable_cache, cache_timeout, force=False):
@@ -313,8 +310,6 @@ def get_schema_names(cls, inspector, db_id,
@classmethod
@cache_util.memoized_func(
- enable_cache=lambda *args, **kwargs: kwargs.get('enable_cache', False),
- timeout=lambda *args, **kwargs: kwargs.get('cache_timeout'),
key=lambda *args, **kwargs: 'db:{db_id}:schema:{schema}:table_list'.format(
db_id=kwargs.get('db_id'), schema=kwargs.get('schema')))
def get_table_names(cls, inspector, db_id, schema,
@@ -323,8 +318,6 @@ def get_table_names(cls, inspector, db_id, schema,
@classmethod
@cache_util.memoized_func(
- enable_cache=lambda *args, **kwargs: kwargs.get('enable_cache', False),
- timeout=lambda *args, **kwargs: kwargs.get('cache_timeout'),
key=lambda *args, **kwargs: 'db:{db_id}:schema:{schema}:view_list'.format(
db_id=kwargs.get('db_id'), schema=kwargs.get('schema')))
def get_view_names(cls, inspector, db_id, schema,
@@ -455,8 +448,6 @@ class PostgresEngineSpec(PostgresBaseEngineSpec):
@classmethod
@cache_util.memoized_func(
- enable_cache=lambda *args, **kwargs: kwargs.get('enable_cache', False),
- timeout=lambda *args, **kwargs: kwargs.get('cache_timeout'),
key=lambda *args, **kwargs: 'db:{db_id}:schema:{schema}:table_list'.format(
db_id=kwargs.get('db_id'), schema=kwargs.get('schema')))
def get_table_names(cls, inspector, db_id, schema,
@@ -592,7 +583,6 @@ def epoch_to_dttm(cls):
@classmethod
@cache_util.memoized_func(
- timeout=600,
key=lambda *args, **kwargs: 'db:{}:{}'.format(args[0].id, args[1]),
use_tables_cache=True)
def fetch_result_sets(cls, db, datasource_type, force=False):
@@ -619,8 +609,6 @@ def convert_dttm(cls, target_type, dttm):
@classmethod
@cache_util.memoized_func(
- enable_cache=lambda *args, **kwargs: kwargs.get('enable_cache', False),
- timeout=lambda *args, **kwargs: kwargs.get('cache_timeout'),
key=lambda *args, **kwargs: 'db:{db_id}:schema:{schema}:table_list'.format(
db_id=kwargs.get('db_id'), schema=kwargs.get('schema')))
def get_table_names(cls, inspector, db_id, schema,
@@ -749,7 +737,6 @@ def epoch_to_dttm(cls):
@classmethod
@cache_util.memoized_func(
- timeout=600,
key=lambda *args, **kwargs: 'db:{}:{}'.format(args[0].id, args[1]),
use_tables_cache=True)
def fetch_result_sets(cls, db, datasource_type, force=False):
@@ -1031,7 +1018,6 @@ def patch(cls):
@classmethod
@cache_util.memoized_func(
- timeout=600,
key=lambda *args, **kwargs: 'db:{}:{}'.format(args[0].id, args[1]),
use_tables_cache=True)
def fetch_result_sets(cls, db, datasource_type, force=False):
@@ -1489,8 +1475,6 @@ def convert_dttm(cls, target_type, dttm):
@classmethod
@cache_util.memoized_func(
- enable_cache=lambda *args, **kwargs: kwargs.get('enable_cache', False),
- timeout=lambda *args, **kwargs: kwargs.get('cache_timeout'),
key=lambda *args, **kwargs: 'db:{}:schema_list'.format(kwargs.get('db_id')))
def get_schema_names(cls, inspector, db_id,
enable_cache, cache_timeout, force=False):