From 042052aec61b8c51751cb3aeb27c6c21ecf16416 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Tue, 2 May 2017 09:28:44 -0400
Subject: Improve perf for channel switching, fix team switching issues (#6286)

* Improve perf for channel switching, fix team switching issues

* Fix last channel when switching teams
---
 webapp/components/sidebar.jsx | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

(limited to 'webapp/components/sidebar.jsx')

diff --git a/webapp/components/sidebar.jsx b/webapp/components/sidebar.jsx
index 71559de02..465d25576 100644
--- a/webapp/components/sidebar.jsx
+++ b/webapp/components/sidebar.jsx
@@ -116,14 +116,19 @@ export default class Sidebar extends React.Component {
         const currentChannelId = ChannelStore.getCurrentId();
         const tutorialStep = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), 999);
 
-        const allChannels = ChannelStore.getAll().map((channel) => Object.assign({}, channel));
-        const channelList = ChannelUtils.buildDisplayableChannelList(allChannels);
+        const channels = ChannelStore.getAll();
+        let displayableChannels = {};
+        if (channels !== this.oldChannels) {
+            const channelsArray = channels.map((channel) => Object.assign({}, channel));
+            displayableChannels = ChannelUtils.buildDisplayableChannelList(channelsArray);
+        }
+        this.oldChannels = channels;
 
         return {
             activeId: currentChannelId,
             members,
             teamMembers,
-            ...channelList,
+            ...displayableChannels,
             unreadCounts: JSON.parse(JSON.stringify(ChannelStore.getUnreadCounts())),
             showTutorialTip: tutorialStep === TutorialSteps.CHANNEL_POPOVER,
             currentTeam: TeamStore.getCurrent(),
-- 
cgit v1.2.3-1-g7c22

