diff --git a/superset/views/core.py b/superset/views/core.py index 4f392337902b8..cab65fd37b668 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -1137,38 +1137,24 @@ def tables( # pylint: disable=too-many-locals,no-self-use,too-many-arguments schema_parsed = utils.parse_js_uri_path_item(schema, eval_undefined=True) substr_parsed = utils.parse_js_uri_path_item(substr, eval_undefined=True) - if schema_parsed: - tables = [ - utils.DatasourceName(*datasource_name) - for datasource_name in database.get_all_table_names_in_schema( - schema=schema_parsed, - force=force_refresh_parsed, - cache=database.table_cache_enabled, - cache_timeout=database.table_cache_timeout, - ) - ] or [] - views = [ - utils.DatasourceName(*datasource_name) - for datasource_name in database.get_all_view_names_in_schema( - schema=schema_parsed, - force=force_refresh_parsed, - cache=database.table_cache_enabled, - cache_timeout=database.table_cache_timeout, - ) - ] or [] - else: - tables = [ - utils.DatasourceName(*datasource_name) - for datasource_name in database.get_all_table_names_in_database( - cache=True, force=False, cache_timeout=24 * 60 * 60 - ) - ] - views = [ - utils.DatasourceName(*datasource_name) - for datasource_name in database.get_all_view_names_in_database( - cache=True, force=False, cache_timeout=24 * 60 * 60 - ) - ] + tables = [ + utils.DatasourceName(*datasource_name) + for datasource_name in database.get_all_table_names_in_schema( + schema=schema_parsed, + force=force_refresh_parsed, + cache=database.table_cache_enabled, + cache_timeout=database.table_cache_timeout, + ) + ] or [] + views = [ + utils.DatasourceName(*datasource_name) + for datasource_name in database.get_all_view_names_in_schema( + schema=schema_parsed, + force=force_refresh_parsed, + cache=database.table_cache_enabled, + cache_timeout=database.table_cache_timeout, + ) + ] or [] tables = security_manager.get_datasources_accessible_by_user( database, tables, schema_parsed ) @@ -1177,9 +1163,7 @@ def tables( # pylint: disable=too-many-locals,no-self-use,too-many-arguments ) def get_datasource_label(ds_name: utils.DatasourceName) -> str: - return ( - ds_name.table if schema_parsed else f"{ds_name.schema}.{ds_name.table}" - ) + return ds_name.table def is_match(src: str, target: utils.DatasourceName) -> bool: target_label = get_datasource_label(target) @@ -1191,22 +1175,10 @@ def is_match(src: str, target: utils.DatasourceName) -> bool: tables = [tn for tn in tables if is_match(substr_parsed, tn)] views = [vn for vn in views if is_match(substr_parsed, vn)] - if not schema_parsed and database.default_schemas: - user_schemas = ( - [g.user.email.split("@")[0]] if hasattr(g.user, "email") else [] - ) - valid_schemas = set(database.default_schemas + user_schemas) - - tables = [tn for tn in tables if tn.schema in valid_schemas] - views = [vn for vn in views if vn.schema in valid_schemas] - - max_items = config["MAX_TABLE_NAMES"] or len(tables) - total_items = len(tables) + len(views) max_tables = len(tables) max_views = len(views) - if total_items and substr_parsed: - max_tables = max_items * len(tables) // total_items - max_views = max_items * len(views) // total_items + total_items = len(tables) + len(views) + max_items = config["MAX_TABLE_NAMES"] or total_items extra_dict_by_name = { table.name: table.extra_dict @@ -1243,7 +1215,7 @@ def is_match(src: str, target: utils.DatasourceName) -> bool: ] ) table_options.sort(key=lambda value: value["label"]) - payload = {"tableLength": len(tables) + len(views), "options": table_options} + payload = {"tableLength": total_items, "options": table_options[:max_items]} return json_success(json.dumps(payload)) @api