From 6f248cd4d3df8d58a5d3da033324c0f6cb6d19ec Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Thu, 6 Jul 2023 17:47:52 -0700 Subject: [PATCH] Address comments --- superset/config.py | 2 +- superset/dashboards/api.py | 2 +- superset/models/dashboard.py | 5 +++-- superset/utils/dashboard_import_export.py | 4 ++-- superset/views/dashboard/views.py | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/superset/config.py b/superset/config.py index ae426a08fcf1e..7ccb3a57fbac7 100644 --- a/superset/config.py +++ b/superset/config.py @@ -264,7 +264,7 @@ def _try_json_readsha(filepath: str, length: int) -> str | None: # Configuration for scheduling queries from SQL Lab. SCHEDULED_QUERIES: dict[str, Any] = {} -# Rate limiting +# FAB Rate limiting RATELIMIT_ENABLED = True AUTH_RATE_LIMITED = True AUTH_RATE_LIMIT = "2 per 5 second" diff --git a/superset/dashboards/api.py b/superset/dashboards/api.py index be248f7877f5f..1de27dfe58066 100644 --- a/superset/dashboards/api.py +++ b/superset/dashboards/api.py @@ -826,7 +826,7 @@ def export(self, **kwargs: Any) -> Response: Dashboard.id.in_(requested_ids) ) query = self._base_filters.apply_all(query) - ids = [item.id for item in query.all()] + ids = {item.id for item in query.all()} if not ids: return self.response_404() export = Dashboard.export_dashboards(ids) diff --git a/superset/models/dashboard.py b/superset/models/dashboard.py index 757a97d06ecf6..5eb4500116577 100644 --- a/superset/models/dashboard.py +++ b/superset/models/dashboard.py @@ -378,11 +378,12 @@ def clear_cache_for_datasource(cls, datasource_id: int) -> None: @classmethod def export_dashboards( # pylint: disable=too-many-locals - cls, dashboard_ids: list[int] + cls, + dashboard_ids: set[int], ) -> str: copied_dashboards = [] datasource_ids = set() - for dashboard_id in set(dashboard_ids): + for dashboard_id in dashboard_ids: # make sure that dashboard_id is an integer dashboard_id = int(dashboard_id) dashboard = ( diff --git a/superset/utils/dashboard_import_export.py b/superset/utils/dashboard_import_export.py index fc61d0a422d0c..eef8cbe6df1cd 100644 --- a/superset/utils/dashboard_import_export.py +++ b/superset/utils/dashboard_import_export.py @@ -27,8 +27,8 @@ def export_dashboards(session: Session) -> str: """Returns all dashboards metadata as a json dump""" logger.info("Starting export") dashboards = session.query(Dashboard) - dashboard_ids = [] + dashboard_ids = set() for dashboard in dashboards: - dashboard_ids.append(dashboard.id) + dashboard_ids.add(dashboard.id) data = Dashboard.export_dashboards(dashboard_ids) return data diff --git a/superset/views/dashboard/views.py b/superset/views/dashboard/views.py index 71ef212f6d42c..ba8b8b2fb3973 100644 --- a/superset/views/dashboard/views.py +++ b/superset/views/dashboard/views.py @@ -78,7 +78,7 @@ def mulexport( # pylint: disable=no-self-use @expose("/export_dashboards_form") def download_dashboards(self) -> FlaskResponse: if request.args.get("action") == "go": - ids = request.args.getlist("id") + ids = set(request.args.getlist("id")) return Response( DashboardModel.export_dashboards(ids), headers=generate_download_headers("json"),