Skip to content

Commit

Permalink
Update cache for the command line command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Kyryliuk committed Feb 22, 2017
1 parent 1e47d6f commit 8cfb8a8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion superset/cache_util.py
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions superset/cli.py
Expand Up @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions superset/db_engine_specs.py
Expand Up @@ -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'.
Expand Down Expand Up @@ -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'.
Expand Down
10 changes: 6 additions & 4 deletions superset/models.py
Expand Up @@ -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:
Expand Down

0 comments on commit 8cfb8a8

Please sign in to comment.