superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: Allow 'refresh_immune_slices' (#2974)
Date Wed, 02 Aug 2017 15:46:23 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 163f4e3  Allow 'refresh_immune_slices' (#2974)
163f4e3 is described below

commit 163f4e359cda11f7df60a32c4fbca40cd561a52e
Author: Rich @ RadICS <rich@radics.co.uk>
AuthorDate: Wed Aug 2 17:46:19 2017 +0200

    Allow 'refresh_immune_slices' (#2974)
    
    * Allow 'refresh_immune_slices'
    
    * Changed param name, added note in FAQ
    
    * Linting
---
 docs/faq.rst                                        | 21 ++++++++++++++++++++-
 superset/assets/javascripts/dashboard/Dashboard.jsx | 13 ++++++++-----
 .../assets/spec/javascripts/dashboard/fixtures.jsx  |  1 +
 superset/models/core.py                             |  8 ++++++++
 superset/views/core.py                              |  2 ++
 5 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/docs/faq.rst b/docs/faq.rst
index 1777ca4..3fc8cef 100644
--- a/docs/faq.rst
+++ b/docs/faq.rst
@@ -107,7 +107,8 @@ never be affected by any dashboard level filtering.
         "filter_immune_slice_fields": {
             "177": ["country_name", "__from", "__to"],
             "32": ["__from", "__to"]
-        }
+        },
+        "timed_refresh_immune_slices": [324]
     }
 
 In the json blob above, slices 324, 65 and 92 won't be affected by any
@@ -124,6 +125,24 @@ But what happens with filtering when dealing with slices coming from
 different tables or databases? If the column name is shared, the filter will
 be applied, it's as simple as that.
 
+
+How to limit the timed refresh on a dashboard?
+----------------------------------------------
+By default, the dashboard timed refresh feature allows you to automatically requery every
slice on a dashboard according to a set schedule. Sometimes, however, you won't want all of
the slices to be refreshed - especially if some data is slow moving, or run heavy queries.
+To exclude specific slices from the timed refresh process, add the ``timed_refresh_immune_slices``
key to the dashboard ``JSON Metadata`` field:
+
+..code::
+
+    {
+       "filter_immune_slices": [],
+        "expanded_slices": {},
+        "filter_immune_slice_fields": {},
+        "timed_refresh_immune_slices": [324]
+    }
+
+In the example above, if a timed refresh is set for the dashboard, then every slice except
324 will be automatically requeried on schedule.
+
+
 Why does fabmanager or superset freezed/hung/not responding when started (my home directory
is NFS mounted)?
 -----------------------------------------------------------------------------------------
 superset creates and uses an sqlite database at ``~/.superset/superset.db``. Sqlite is known
to `don't work well if used on NFS`__ due to broken file locking implementation on NFS.
diff --git a/superset/assets/javascripts/dashboard/Dashboard.jsx b/superset/assets/javascripts/dashboard/Dashboard.jsx
index 8b0a0e1..b6c97b6 100644
--- a/superset/assets/javascripts/dashboard/Dashboard.jsx
+++ b/superset/assets/javascripts/dashboard/Dashboard.jsx
@@ -245,15 +245,18 @@ export function dashboardContainer(dashboard, datasources, userid) {
     startPeriodicRender(interval) {
       this.stopPeriodicRender();
       const dash = this;
+      const immune = this.metadata.timed_refresh_immune_slices || [];
       const maxRandomDelay = Math.max(interval * 0.2, 5000);
       const refreshAll = () => {
         dash.sliceObjects.forEach((slice) => {
           const force = !dash.firstLoad;
-          setTimeout(() => {
-            slice.render(force);
-          },
-          // Randomize to prevent all widgets refreshing at the same time
-          maxRandomDelay * Math.random());
+          if (immune.indexOf(slice.data.slice_id) === -1) {
+            setTimeout(() => {
+              slice.render(force);
+            },
+            // Randomize to prevent all widgets refreshing at the same time
+            maxRandomDelay * Math.random());
+          }
         });
         dash.firstLoad = false;
       };
diff --git a/superset/assets/spec/javascripts/dashboard/fixtures.jsx b/superset/assets/spec/javascripts/dashboard/fixtures.jsx
index 7ac259e..7c822d7 100644
--- a/superset/assets/spec/javascripts/dashboard/fixtures.jsx
+++ b/superset/assets/spec/javascripts/dashboard/fixtures.jsx
@@ -43,6 +43,7 @@ export const dashboardData = {
   css: '',
   metadata: {
     filter_immune_slices: [],
+    timed_refresh_immune_slices: [],
     filter_immune_slice_fields: {},
     expanded_slices: {},
   },
diff --git a/superset/models/core.py b/superset/models/core.py
index 5527f11..43cbeff 100644
--- a/superset/models/core.py
+++ b/superset/models/core.py
@@ -411,6 +411,7 @@ class Dashboard(Model, AuditMixinNullable, ImportMixin):
         slices = copy(dashboard_to_import.slices)
         old_to_new_slc_id_dict = {}
         new_filter_immune_slices = []
+        new_timed_refresh_immune_slices = []
         new_expanded_slices = {}
         i_params_dict = dashboard_to_import.params_dict
         for slc in slices:
@@ -424,6 +425,10 @@ class Dashboard(Model, AuditMixinNullable, ImportMixin):
             if ('filter_immune_slices' in i_params_dict and
                     old_slc_id_str in i_params_dict['filter_immune_slices']):
                 new_filter_immune_slices.append(new_slc_id_str)
+            if ('timed_refresh_immune_slices' in i_params_dict and
+                    old_slc_id_str in
+                        i_params_dict['timed_refresh_immune_slices']):
+                new_timed_refresh_immune_slices.append(new_slc_id_str)
             if ('expanded_slices' in i_params_dict and
                     old_slc_id_str in i_params_dict['expanded_slices']):
                 new_expanded_slices[new_slc_id_str] = (
@@ -446,6 +451,9 @@ class Dashboard(Model, AuditMixinNullable, ImportMixin):
         if new_filter_immune_slices:
             dashboard_to_import.alter_params(
                 filter_immune_slices=new_filter_immune_slices)
+        if new_timed_refresh_immune_slices:
+            dashboard_to_import.alter_params(
+                timed_refresh_immune_slices=new_timed_refresh_immune_slices)
 
         new_slices = session.query(Slice).filter(
             Slice.id.in_(old_to_new_slc_id_dict.values())).all()
diff --git a/superset/views/core.py b/superset/views/core.py
index e73ddc8..a10e884 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1343,6 +1343,8 @@ class Superset(BaseSupersetView):
 
         if 'filter_immune_slices' not in md:
             md['filter_immune_slices'] = []
+        if 'timed_refresh_immune_slices' not in md:
+            md['timed_refresh_immune_slices'] = []
         if 'filter_immune_slice_fields' not in md:
             md['filter_immune_slice_fields'] = {}
         md['expanded_slices'] = data['expanded_slices']

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message