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_r391077356
##########
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:
It's always better to return a 304 :). The digest will change when the
underlying thumbnail does, I'm assuming. Therefore the frontend will bust
through anything that's cached 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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]