You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/03/10 17:49:15 UTC
[GitHub] [incubator-superset] craig-rueda commented on a change in pull
request #8947: [thumbnails] thumbnails for dashboards and charts
craig-rueda commented on a change in pull request #8947: [thumbnails] thumbnails for dashboards and charts
URL: https://github.com/apache/incubator-superset/pull/8947#discussion_r390498816
##########
File path: superset/views/chart/api.py
##########
@@ -173,3 +189,62 @@ class ChartRestApi(SliceMixin, BaseOwnedModelRestApi):
"owners": ("first_name", "asc"),
}
filter_rel_fields_field = {"owners": "first_name", "dashboards": "dashboard_title"}
+
+ def __init__(self, *args, **kwargs):
+ if is_feature_enabled("THUMBNAILS"):
+ self.include_route_methods = self.include_route_methods | {"thumbnail"}
+ super().__init__(*args, **kwargs)
+
+ @expose("/<pk>/thumbnail/<digest>/", methods=["GET"])
+ @protect()
+ @rison(thumbnail_query_schema)
+ @safe
+ def thumbnail(self, pk, digest, **kwargs): # pylint: disable=invalid-name
+ """Get Chart thumbnail
+ ---
+ get:
+ description: Compute or get already computed chart thumbnail from cache
+ parameters:
+ - in: path
+ schema:
+ type: integer
+ name: pk
+ - in: path
+ schema:
+ type: string
+ name: sha
+ responses:
+ 200:
+ description: Chart thumbnail image
+ content:
+ image/*:
+ schema:
+ type: string
+ format: binary
+ 401:
+ $ref: '#/components/responses/401'
+ 404:
+ $ref: '#/components/responses/404'
+ 422:
+ $ref: '#/components/responses/422'
+ 500:
+ $ref: '#/components/responses/500'
+ """
+ chart = self.datamodel.get(pk, self._base_filters)
+ if not chart:
+ return self.response_404()
+ if kwargs["rison"].get("force", False):
+ cache_chart_thumbnail.delay(chart.id, force=True)
+ return self.response(202, message="OK Async")
+ # fetch the chart screenshot using the current user and cache if set
+ screenshot = ChartScreenshot(pk).get_from_cache(cache=thumbnail_cache)
+ # If not screenshot then send request to compute thumb to celery
+ if not screenshot:
+ cache_chart_thumbnail.delay(chart.id, force=True)
+ return self.response(202, message="OK Async")
+ # If digests
+ if chart.unique_value != digest:
+ logger.info("Requested thumbnail digest differs from actual digest")
+ return Response(
Review comment:
Do we want to add any browser cache headers here? The thing should be able to be cached almost indefinitely, as it would need to be recomputed on update.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org