john-bodley opened a new pull request #9375: [cache] Cleaning up viz/cache logic
URL: https://github.com/apache/incubator-superset/pull/9375
 
 
   ### CATEGORY
   
   Choose one
   
   - [ ] Bug Fix
   - [x] Enhancement (new features, refinement)
   - [ ] Refactor
   - [ ] Add tests
   - [ ] Build / Development Environment
   - [ ] Documentation
   
   ### SUMMARY
   
   Whilst looking into the chart caching logic I got tripped up on a few issues 
specifically: 
   
   1. There were two `get_viz` methods which were near identical and 
`views.utils.get_viz` and `views.core.Superset:get_viz` and only the former was 
being used. 
   2. These methods where not forcing a new query if the `slice_id` was 
defined, i.e., 
   
   ```python
    if slice_id:        
       slc = db.session.query(Slice).filter_by(id=slice_id).one()       
       return slc.get_viz()
   ```
   
   one would expect the last line to read `return slc.get_viz(force=force)`. 
Upon further investigation it seems like the only place that was calling the 
`get_viz` method with the `slice_id` argument was the obsolete 
`/slice_query/<slice_id>/` route (I checked it wasn't being used in 
[superset-ui](https://github.com/apache-superset/superset-ui/search?q=slice_query&unscoped_q=slice_query)
 repo as well) and thus jettisoned  the endpoint and the 
`models.slices.Slice:get_viz` method. 
   
   3. The statsD logging for `loaded_from_source` (which is useful for 
determining the cache hit rate, i.e., `loaded_from_cache` / 
(`loaded_from_cache` + `loaded_from_source`) was agnostic of whether the it was 
loaded because of force load and thus the denominator is over counting. Ideally 
an `is_force` tag would be beneficial however statsD doesn't support these 
(Datadog does though) and thus I updated the logic to only increment the 
`loaded_from_source` counter if it is not forced. The other option is to leave 
the logic unchanged and add a `loaded_from_cache_non_forced` (or similar) 
counter.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TEST PLAN
   
   CI.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Changes UI
   - [ ] Requires DB Migration.
   - [ ] Confirm DB Migration upgrade and downgrade tested.
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   ### REVIEWERS
   
   to: @etr2460 @graceguo-supercat @villebro 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to