From 8f0f772a386fa48a851a20e1cc60f85792cb052e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Atte=20Kein=C3=A4nen?= <atte.keinanen@gmail.com>
Date: Tue, 26 Sep 2017 21:46:35 +0300
Subject: [PATCH] Fix perf problems where xray viz was rerendered unnecessarily

---
 .../components/LoadingAndErrorWrapper.jsx     |  8 ++----
 .../metabase/xray/containers/TableXRay.jsx    |  4 +--
 frontend/src/metabase/xray/selectors.js       | 28 ++++---------------
 3 files changed, 10 insertions(+), 30 deletions(-)

diff --git a/frontend/src/metabase/components/LoadingAndErrorWrapper.jsx b/frontend/src/metabase/components/LoadingAndErrorWrapper.jsx
index ac74ad40eea..03920fc6879 100644
--- a/frontend/src/metabase/components/LoadingAndErrorWrapper.jsx
+++ b/frontend/src/metabase/components/LoadingAndErrorWrapper.jsx
@@ -62,11 +62,9 @@ export default class LoadingAndErrorWrapper extends Component {
     }
 
     loadingInterval = () => {
-        this.cycleLoadingMessage()
-    }
-
-    cycleLoadingScenes = () => {
-
+        if (this.props.loading) {
+            this.cycleLoadingMessage()
+        }
     }
 
     getChildren() {
diff --git a/frontend/src/metabase/xray/containers/TableXRay.jsx b/frontend/src/metabase/xray/containers/TableXRay.jsx
index 8e98312718d..0bd19ac21c3 100644
--- a/frontend/src/metabase/xray/containers/TableXRay.jsx
+++ b/frontend/src/metabase/xray/containers/TableXRay.jsx
@@ -11,7 +11,7 @@ import CostSelect from 'metabase/xray/components/CostSelect'
 import Constituent from 'metabase/xray/components/Constituent'
 
 import {
-    getTableConstituents,
+    getConstituents,
     getFeatures,
     getLoadingStatus,
     getError
@@ -42,7 +42,7 @@ type Props = {
 
 const mapStateToProps = state => ({
     xray: getFeatures(state),
-    constituents: getTableConstituents(state),
+    constituents: getConstituents(state),
     isLoading: getLoadingStatus(state),
     error: getError(state)
 })
diff --git a/frontend/src/metabase/xray/selectors.js b/frontend/src/metabase/xray/selectors.js
index bc0285e7c2a..69e6365b312 100644
--- a/frontend/src/metabase/xray/selectors.js
+++ b/frontend/src/metabase/xray/selectors.js
@@ -13,27 +13,11 @@ export const getXray = (state) =>
 export const getFeatures = (state) =>
     state.xray.xray && state.xray.xray.features
 
-/* TODO - these can be collapsed into getConstituents */
-export const getTableConstituents = (state) => {
-    return state.xray.xray && (
-        Object.keys(state.xray.xray.constituents).map(key =>
-            state.xray.xray.constituents[key]
-        )
-    )
-}
-export const getSegmentConstituents = (state) =>
-    state.xray.xray && (
-        Object.keys(state.xray.xray.constituents).map(key =>
-            state.xray.xray.constituents[key]
-        )
-    )
-
-export const getConstituents = (state) =>
-    state.xray.xray && (
-        Object.keys(state.xray.xray.constituents).map(key =>
-            state.xray.xray.constituents[key]
-        )
-    )
+
+export const getConstituents = createSelector(
+    [getXray],
+    (xray) => xray && Object.values(xray.constituents)
+)
 
 export const getComparison = (state) => state.xray.comparison
 
@@ -123,8 +107,6 @@ export const getTableItem = (state, index = 1) => createSelector(
     }
 )(state)
 
-export const getComparisonForField = createSelector
-
 // see if xrays are enabled. unfortunately enabled can equal null so its enabled if its not false
 export const getXrayEnabled = state => {
     const enabled = state.settings.values && state.settings.values['enable_xrays']
-- 
GitLab