This is an automated email from the ASF dual-hosted git repository.
beto pushed a commit to branch lyftga
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/lyftga by this push:
new 4bc69c0 limit tables/views returned if schema is not provided (#7358)
4bc69c0 is described below
commit 4bc69c0a61d1a832c61dccd0ecd0ea537998fe4f
Author: Thomas Wang <[email protected]>
AuthorDate: Tue Apr 23 13:51:46 2019 -0700
limit tables/views returned if schema is not provided (#7358)
* limit tables/views returned if schema is not provided
* fix typo
* improve code performance
* handle the case when table name or view name does not present a schema
---
superset/models/core.py | 4 ++++
superset/views/core.py | 10 ++++++++++
2 files changed, 14 insertions(+)
diff --git a/superset/models/core.py b/superset/models/core.py
index b848604..0486245 100644
--- a/superset/models/core.py
+++ b/superset/models/core.py
@@ -748,6 +748,10 @@ class Database(Model, AuditMixinNullable, ImportMixin):
def table_cache_timeout(self):
return self.metadata_cache_timeout.get('table_cache_timeout')
+ @property
+ def default_schemas(self):
+ return self.get_extra().get('default_schemas', [])
+
@classmethod
def get_password_masked_url_from_uri(cls, uri):
url = make_url(uri)
diff --git a/superset/views/core.py b/superset/views/core.py
index becc1b1..d8953d7 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1513,6 +1513,16 @@ class Superset(BaseSupersetView):
table_names = [tn for tn in table_names if substr in tn]
view_names = [vn for vn in view_names if substr in vn]
+ if not schema and database.default_schemas:
+ def get_schema(tbl_or_view_name):
+ return tbl_or_view_name.split('.')[0] if '.' in
tbl_or_view_name else None
+
+ user_schema = g.user.email.split('@')[0]
+ valid_schemas = set(database.default_schemas + [user_schema])
+
+ table_names = [tn for tn in table_names if get_schema(tn) in
valid_schemas]
+ view_names = [vn for vn in view_names if get_schema(vn) in
valid_schemas]
+
max_items = config.get('MAX_TABLE_NAMES') or len(table_names)
total_items = len(table_names) + len(view_names)
max_tables = len(table_names)