Update cache for the command line command. (#2213)

This commit is contained in:
Bogdan 2017-02-22 12:06:48 -08:00 committed by GitHub
parent 3e0d3584f7
commit 3a91667e92
4 changed files with 11 additions and 9 deletions

View File

@ -19,7 +19,7 @@ def memoized_func(timeout=5 * 60, key=view_cache_key):
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)

View File

@ -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))

View File

@ -61,7 +61,7 @@ class BaseEngineSpec(object):
@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 @@ class PrestoEngineSpec(BaseEngineSpec):
@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'.

View File

@ -852,15 +852,17 @@ class Database(Model, AuditMixinNullable):
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: