Skip to content

Commit

Permalink
Slice level cache_timeout isn't taken into consideration (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch authored Apr 17, 2017
1 parent 70c6cad commit 23aeee5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
7 changes: 7 additions & 0 deletions superset/assets/javascripts/explorev2/stores/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1199,5 +1199,12 @@ export const controls = {
hidden: true,
description: 'The id of the active slice',
},

cache_timeout: {
type: 'HiddenControl',
label: 'Cache Timeout (seconds)',
hidden: true,
description: 'The number of seconds before expiring the cache',
},
};
export default controls;
2 changes: 1 addition & 1 deletion superset/assets/javascripts/explorev2/stores/visTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const sections = {
controlSetRows: [
['datasource'],
['viz_type'],
['slice_id'],
['slice_id', 'cache_timeout'],
],
},
sqlaTimeSeries: {
Expand Down
13 changes: 7 additions & 6 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from superset import app, db, db_engine_specs, utils, sm
from superset.connectors.connector_registry import ConnectorRegistry
from superset.viz import viz_types
from superset.utils import QueryStatus
from superset.models.helpers import AuditMixinNullable, ImportMixin, set_perm
install_aliases()
from urllib import parse # noqa
Expand Down Expand Up @@ -181,10 +180,13 @@ def json_data(self):
@property
def form_data(self):
form_data = json.loads(self.params)
form_data['slice_id'] = self.id
form_data['viz_type'] = self.viz_type
form_data['datasource'] = (
str(self.datasource_id) + '__' + self.datasource_type)
form_data.update({
'slice_id': self.id,
'viz_type': self.viz_type,
'datasource': str(self.datasource_id) + '__' + self.datasource_type
})
if self.cache_timeout:
form_data['cache_timeout'] = self.cache_timeout
return form_data

@property
Expand Down Expand Up @@ -230,7 +232,6 @@ def get_viz(self, url_params_multidict=None):
return viz_types[slice_params.get('viz_type')](
self.datasource,
form_data=slice_params,
slice_=self
)

@classmethod
Expand Down
3 changes: 1 addition & 2 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
sm, sql_lab, results_backend, security,
)
from superset.legacy import cast_form_data
from superset.utils import has_access
from superset.utils import has_access, QueryStatus
from superset.connectors.connector_registry import ConnectorRegistry
import superset.models.core as models
from superset.models.sql_lab import Query
Expand All @@ -47,7 +47,6 @@
config = app.config
log_this = models.Log.log_this
can_access = utils.can_access
QueryStatus = models.QueryStatus
DAR = models.DatasourceAccessRequest


Expand Down
8 changes: 3 additions & 5 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ class BaseViz(object):
credits = ""
is_timeseries = False

def __init__(self, datasource, form_data, slice_=None):
def __init__(self, datasource, form_data):
if not datasource:
raise Exception("Viz is missing a datasource")
self.datasource = datasource
self.request = request
self.viz_type = form_data.get("viz_type")
self.slice = slice_
self.form_data = form_data

self.query = ""
Expand Down Expand Up @@ -184,9 +183,8 @@ def query_obj(self):

@property
def cache_timeout(self):

if self.slice and self.slice.cache_timeout:
return self.slice.cache_timeout
if self.form_data.get('cache_timeout'):
return int(self.form_data.get('cache_timeout'))
if self.datasource.cache_timeout:
return self.datasource.cache_timeout
if (
Expand Down

0 comments on commit 23aeee5

Please sign in to comment.