[cache] Allowing zero cache-timeout (#5315)

This commit is contained in:
John Bodley 2018-07-02 15:32:21 -07:00 committed by GitHub
parent 16d26336c4
commit 72d815c0f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 4 deletions

View File

@ -176,6 +176,11 @@ class DruidClusterModelView(SupersetModelView, DeleteMixin, YamlExportMixin): #
'broker_port': _('Broker Port'),
'broker_endpoint': _('Broker Endpoint'),
}
description_columns = {
'cache_timeout': _(
'Duration (in seconds) of the caching timeout for this cluster. '
'Note this defaults to the global timeout if undefined.'),
}
def pre_add(self, cluster):
security_manager.merge_perm('database_access', cluster.perm)
@ -249,6 +254,9 @@ class DruidDatasourceModelView(DatasourceModelView, DeleteMixin, YamlExportMixin
'default_endpoint': _(
'Redirects to this endpoint when clicking on the datasource '
'from the datasource list'),
'cache_timeout': _(
'Duration (in seconds) of the caching timeout for this datasource. '
'Note this defaults to the cluster timeout if undefined.'),
}
base_filters = [['id', DatasourceFilter, lambda: []]]
label_columns = {

View File

@ -219,6 +219,9 @@ class TableModelView(DatasourceModelView, DeleteMixin, YamlExportMixin): # noqa
'template_params': _(
'A set of parameters that become available in the query using '
'Jinja templating syntax'),
'cache_timeout': _(
'Duration (in seconds) of the caching timeout for this table. '
'Note this defaults to the database timeout if undefined.'),
}
label_columns = {
'slices': _('Associated Charts'),

View File

@ -266,6 +266,9 @@ class DatabaseView(SupersetModelView, DeleteMixin, YamlExportMixin): # noqa
'Allow SQL Lab to fetch a list of all tables and all views across '
'all database schemas. For large data warehouse with thousands of '
'tables, this can be expensive and put strain on the system.'),
'cache_timeout': _(
'Duration (in seconds) of the caching timeout for this database. '
'Note this defaults to the global timeout if undefined.'),
}
label_columns = {
'expose_in_sqllab': _('Expose in SQL Lab'),
@ -450,7 +453,8 @@ class SliceModelView(SupersetModelView, DeleteMixin): # noqa
'want to alter specific parameters.',
),
'cache_timeout': _(
'Duration (in seconds) of the caching timeout for this chart.'),
'Duration (in seconds) of the caching timeout for this chart. '
'Note this defaults to the datasource/table timeout if undefined.'),
}
base_filters = [['id', SliceFilter, lambda: []]]
label_columns = {

View File

@ -311,13 +311,13 @@ class BaseViz(object):
@property
def cache_timeout(self):
if self.form_data.get('cache_timeout'):
if self.form_data.get('cache_timeout') is not None:
return int(self.form_data.get('cache_timeout'))
if self.datasource.cache_timeout:
if self.datasource.cache_timeout is not None:
return self.datasource.cache_timeout
if (
hasattr(self.datasource, 'database') and
self.datasource.database.cache_timeout):
self.datasource.database.cache_timeout) is not None:
return self.datasource.database.cache_timeout
return config.get('CACHE_DEFAULT_TIMEOUT')

View File

@ -10,6 +10,7 @@ import unittest
from mock import Mock, patch
import pandas as pd
from superset import app
from superset.utils import DTTM_ALIAS
import superset.viz as viz
from .utils import load_fixture
@ -101,13 +102,21 @@ class BaseVizTestCase(unittest.TestCase):
def test_cache_timeout(self):
datasource = Mock()
datasource.cache_timeout = 0
test_viz = viz.BaseViz(datasource, form_data={})
self.assertEqual(0, test_viz.cache_timeout)
datasource.cache_timeout = 156
test_viz = viz.BaseViz(datasource, form_data={})
self.assertEqual(156, test_viz.cache_timeout)
datasource.cache_timeout = None
datasource.database = Mock()
datasource.database.cache_timeout = 0
self.assertEqual(0, test_viz.cache_timeout)
datasource.database.cache_timeout = 1666
self.assertEqual(1666, test_viz.cache_timeout)
datasource.database.cache_timeout = None
test_viz = viz.BaseViz(datasource, form_data={})
self.assertEqual(app.config['CACHE_DEFAULT_TIMEOUT'], test_viz.cache_timeout)
class TableVizTestCase(unittest.TestCase):