You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2024/06/25 13:29:10 UTC

(superset) 12/22: fix image url key inconsistency

This is an automated email from the ASF dual-hosted git repository.

diegopucci pushed a commit to branch geido/feat/dashboard-endpoint-screenshot
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 9f67bb6c2677054c00b49424219edd6a6ab2cda6
Author: Edgar Ulloa <ul...@gmail.com>
AuthorDate: Tue Jun 11 16:47:41 2024 -0700

    fix image url key inconsistency
---
 superset/dashboards/api.py   | 23 ++---------------------
 superset/tasks/thumbnails.py |  6 ++----
 2 files changed, 4 insertions(+), 25 deletions(-)

diff --git a/superset/dashboards/api.py b/superset/dashboards/api.py
index 2448a6ba31..0a298bf707 100644
--- a/superset/dashboards/api.py
+++ b/superset/dashboards/api.py
@@ -890,9 +890,8 @@ class DashboardRestApi(BaseSupersetModelRestApi):
             FileWrapper(screenshot), mimetype="image/png", direct_passthrough=True
         )
 
-    # TODO: Update cache_dashboard_screenshot endpoint
     @expose("/<pk>/cache_dashboard_screenshot/", methods=("POST",))
-    # @protect()
+    @protect()
     @rison(screenshot_query_schema)
     @safe
     @statsd_metrics
@@ -951,12 +950,10 @@ class DashboardRestApi(BaseSupersetModelRestApi):
         """
         try:
             payload = CacheScreenshotSchema().load(request.json)
-            print("PAYLOAD: ", payload)
         except ValidationError as error:
             return self.response_400(message=error.messages)
 
         dashboard = cast(Dashboard, self.datamodel.get(pk, self._base_filters))
-        print("DASHBOARD: ", dashboard)
         if not dashboard:
             return self.response_404()
 
@@ -979,29 +976,18 @@ class DashboardRestApi(BaseSupersetModelRestApi):
         ).run()
 
         dashboard_url = get_url_path("Superset.dashboard_permalink", key=permalink_key)
-
-        # dashboard_url = get_url_path(
-        #     "Superset.dashboard", dashboard_id_or_slug=dashboard.id
-        # )
         screenshot_obj = DashboardScreenshot(dashboard_url, dashboard.digest)
         cache_key = screenshot_obj.cache_key(window_size, thumb_size)
         image_url = get_url_path(
             "DashboardRestApi.screenshot", pk=dashboard.id, digest=cache_key
         )
 
-        print("DASHBOARD ID:", dashboard.id)
-        print("PERMALINK KEY:", permalink_key)
-        print("IMAGE_URL: ", image_url)
-        print("DASHBOARD_URL: ", dashboard_url)
-        print("CACHE_KEY", cache_key)
-
         def trigger_celery() -> WerkzeugResponse:
             logger.info("Triggering screenshot ASYNC")
             cache_dashboard_screenshot.delay(
                 current_user=get_current_user(),
                 dashboard_id=dashboard.id,
                 dashboard_url=dashboard_url,
-                cache_key=cache_key,
                 force=True,
                 thumb_size=thumb_size,
                 window_size=window_size,
@@ -1015,9 +1001,8 @@ class DashboardRestApi(BaseSupersetModelRestApi):
 
         return trigger_celery()
 
-    # TODO:Update Dashboard screenshot endpoint
     @expose("/<pk>/screenshot/<digest>/", methods=("GET",))
-    # @protect()
+    @protect()
     @safe
     @statsd_metrics
     @event_logger.log_this_with_context(
@@ -1061,10 +1046,6 @@ class DashboardRestApi(BaseSupersetModelRestApi):
         if not dashboard:
             return self.response_404()
 
-        print("THUMBNAIL_CACHE: ", dir(thumbnail_cache))
-        print("THUMBNAIL CACHE: ", thumbnail_cache.cache)
-        print("DIGEST", digest)
-
         download_format = request.args.get("download_format", "png")
 
         # fetch the dashboard screenshot using the current user and cache if set
diff --git a/superset/tasks/thumbnails.py b/superset/tasks/thumbnails.py
index 6dd4724362..819356f56e 100644
--- a/superset/tasks/thumbnails.py
+++ b/superset/tasks/thumbnails.py
@@ -106,12 +106,11 @@ def cache_dashboard_thumbnail(
         )
 
 
-@celery_app.task(name="cache_dashboard_screenshot", soft_time_limit=300)
+@celery_app.task(name="cache_dashboard_screenshot", soft_time_limit=60)
 def cache_dashboard_screenshot(
     current_user: Optional[str],
     dashboard_id: int,
     dashboard_url: str,
-    cache_key: str,
     force: bool = False,
     thumb_size: Optional[WindowSize] = None,
     window_size: Optional[WindowSize] = None,
@@ -119,7 +118,6 @@ def cache_dashboard_screenshot(
     # pylint: disable=import-outside-toplevel
     from superset.models.dashboard import Dashboard
 
-    print("CACHE DASHBOARD SCREENSHOT CELERY", dashboard_id, dashboard_url, cache_key)
     if not thumbnail_cache:
         logging.warning("No cache set, refusing to compute")
         return
@@ -134,7 +132,7 @@ def cache_dashboard_screenshot(
     )
     user = security_manager.find_user(username)
     with override_user(user):
-        screenshot = DashboardScreenshot(dashboard_url, cache_key)
+        screenshot = DashboardScreenshot(dashboard_url, dashboard.digest)
         screenshot.compute_and_cache(
             user=user,
             cache=thumbnail_cache,