john-bodley closed pull request #5315: [cache] Providing a mechanism for 
disabling the datasource/database cache
URL: https://github.com/apache/incubator-superset/pull/5315
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/connectors/druid/views.py 
b/superset/connectors/druid/views.py
index 9d2539a46d..9a33c8de4a 100644
--- a/superset/connectors/druid/views.py
+++ b/superset/connectors/druid/views.py
@@ -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 = {
diff --git a/superset/connectors/sqla/views.py 
b/superset/connectors/sqla/views.py
index b46af10157..b8349e57f9 100644
--- a/superset/connectors/sqla/views.py
+++ b/superset/connectors/sqla/views.py
@@ -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'),
diff --git a/superset/views/core.py b/superset/views/core.py
index 7c39f1c6d6..b746a5c24a 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -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 = {
diff --git a/superset/viz.py b/superset/viz.py
index a595e49b68..07be747dd4 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -310,13 +310,13 @@ def query_obj(self):
 
     @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')
 
diff --git a/tests/viz_tests.py b/tests/viz_tests.py
index 1bc6e62a97..474c5500a8 100644
--- a/tests/viz_tests.py
+++ b/tests/viz_tests.py
@@ -10,6 +10,7 @@
 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 @@ def test_get_df_handles_dttm_col(self):
 
     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):


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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]

Reply via email to