GitHub user dosubot[bot] added a comment to the discussion: Thumbnails work for 
Dashboards, not for charts

<!-- Greeting -->
Hey there, @brantian! I'm a bot here to help you with bugs, questions, and 
becoming a contributor. I'm here to assist you while you wait for a human 
maintainer.

<!-- Answer -->
The issue you're encountering with different cache keys for chart thumbnails 
versus dashboard thumbnails likely stems from a discrepancy in how the cache 
keys are generated and used in the code.

For dashboards, the cache keys are consistent, but for charts, it seems there 
is a mismatch. This can be due to differences in the key prefix or the way the 
keys are constructed in the code.

Here are a few steps to troubleshoot and potentially resolve this issue:

1. **Check Cache Key Prefixes**:
   Ensure that the cache key prefixes for charts and dashboards are consistent. 
In your `superset_config.py`, you have:

   ```python
   THUMBNAIL_CACHE_CONFIG: CacheConfig = {
       'CACHE_TYPE': 'RedisCache',
       'CACHE_DEFAULT_TIMEOUT': 7 * 86400,  # 7 days
       'CACHE_KEY_PREFIX': 'thumbnail_',
       'CACHE_REDIS_HOST': REDIS_HOST,
       'CACHE_REDIS_PORT': REDIS_PORT,
       'CACHE_REDIS_DB': REDIS_CELERY_DB
   }
   ```

   Verify that the `CACHE_KEY_PREFIX` is correctly used in both the web app and 
Celery worker for chart thumbnails.

2. **Review Thumbnail Cache Code**:
   Check the code in `superset/tasks/thumbnails.py` where the cache keys are 
generated and used. Ensure that the same logic is applied for both charts and 
dashboards.

   For example, in the `cache_chart_thumbnail` task, ensure the cache key is 
generated consistently:

   ```python
   @celery_app.task(name="cache_chart_thumbnail", soft_time_limit=300)
   def cache_chart_thumbnail(current_user, chart_id, force=False, 
thumb_size=None):
       from superset.models.slice import Slice

       if not thumbnail_cache:
           logging.warning("No cache set, refusing to compute")
           return
       chart = Slice.get(chart_id)
       url = get_url_path("Superset.slice", slice_id=chart.id)

       logger.info("Caching chart: %s", url)
       _, username = get_executor(
           executor_types=current_app.config["THUMBNAIL_EXECUTE_AS"],
           model=chart,
           current_user=current_user,
       )
       user = security_manager.find_user(username)
       with override_user(user):
           screenshot = ChartScreenshot(url, chart.digest)
           screenshot.compute_and_cache(
               user=user,
               cache=thumbnail_cache,
               force=force,
               thumb_size=thumb_size,
           )
   ```

3. **Debug Cache Key Generation**:
   Add debug logs to print out the cache keys being generated in both the web 
app and Celery worker. This will help you identify where the discrepancy occurs.

4. **Ensure Consistent Cache Configuration**:
   Make sure that the `THUMBNAIL_CACHE_CONFIG` is correctly applied in both the 
web app and Celery worker. Sometimes, configuration might not be correctly 
propagated to all parts of the application.

By following these steps, you should be able to identify and resolve the issue 
with inconsistent cache keys for chart thumbnails. If the problem persists, you 
might need to dive deeper into the specific implementation details of the 
thumbnail caching logic in the Superset codebase 
<sup>[[1]](https://github.com/apache/superset/blob/master/superset/tasks/thumbnails.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/docs/docs/configuration/cache.mdx)</sup>.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*


GitHub link: 
https://github.com/apache/superset/discussions/34325#discussioncomment-13893850

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to