From 8cfb8a85d3d0c89c1ef3adb4e2b786409138294f Mon Sep 17 00:00:00 2001 From: Bogdan Kyryliuk Date: Tue, 21 Feb 2017 14:00:42 -0800 Subject: [PATCH] Update cache for the command line command. --- superset/cache_util.py | 2 +- superset/cli.py | 4 ++-- superset/db_engine_specs.py | 4 ++-- superset/models.py | 10 ++++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/superset/cache_util.py b/superset/cache_util.py index 7bef8794af56..ecba03ffa3f1 100644 --- a/superset/cache_util.py +++ b/superset/cache_util.py @@ -19,7 +19,7 @@ def wrap(f): def wrapped_f(cls, *args, **kwargs): cache_key = key(*args, **kwargs) o = tables_cache.get(cache_key) - if o is not None: + if not kwargs['force'] and o is not None: return o o = f(cls, *args, **kwargs) tables_cache.set(cache_key, o, timeout=timeout) diff --git a/superset/cli.py b/superset/cli.py index 04d4b7e3b292..f56faef5548d 100755 --- a/superset/cli.py +++ b/superset/cli.py @@ -156,8 +156,8 @@ def update_datasources_cache(): for database in db.session.query(models.Database).all(): print('Fetching {} datasources ...'.format(database.name)) try: - database.all_table_names() - database.all_view_names() + database.all_table_names(force=True) + database.all_view_names(force=True) except Exception as e: print('{}'.format(e.message)) diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index 59ad5ed29ae5..2bb7159f41e9 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -61,7 +61,7 @@ def convert_dttm(cls, target_type, dttm): @cache_util.memoized_func( timeout=600, key=lambda *args, **kwargs: 'db:{}:{}'.format(args[0].id, args[1])) - def fetch_result_sets(cls, db, datasource_type): + def fetch_result_sets(cls, db, datasource_type, force=False): """Returns the dictionary {schema : [result_set_name]}. Datasource_type can be 'table' or 'view'. @@ -260,7 +260,7 @@ def show_partition_pql( @cache_util.memoized_func( timeout=600, key=lambda *args, **kwargs: 'db:{}:{}'.format(args[0].id, args[1])) - def fetch_result_sets(cls, db, datasource_type): + def fetch_result_sets(cls, db, datasource_type, force=False): """Returns the dictionary {schema : [result_set_name]}. Datasource_type can be 'table' or 'view'. diff --git a/superset/models.py b/superset/models.py index 4e5b55697ab8..cb6cd6cda65a 100644 --- a/superset/models.py +++ b/superset/models.py @@ -852,15 +852,17 @@ def inspector(self): engine = self.get_sqla_engine() return sqla.inspect(engine) - def all_table_names(self, schema=None): + def all_table_names(self, schema=None, force=False): if not schema: - tables_dict = self.db_engine_spec.fetch_result_sets(self, 'table') + tables_dict = self.db_engine_spec.fetch_result_sets( + self, 'table', force=force) return tables_dict.get("", []) return sorted(self.inspector.get_table_names(schema)) - def all_view_names(self, schema=None): + def all_view_names(self, schema=None, force=False): if not schema: - views_dict = self.db_engine_spec.fetch_result_sets(self, 'view') + views_dict = self.db_engine_spec.fetch_result_sets( + self, 'view', force=force) return views_dict.get("", []) views = [] try: