Increase quick switcher perf by not storing server results (#6575)

Этот коммит содержится в:
Joram Wilander
2017-06-05 09:45:50 -04:00
коммит произвёл GitHub
родитель 0d6dd52be6
Коммит 7be7c67757

Просмотреть файл

@@ -14,10 +14,8 @@ import React from 'react';
import store from 'stores/redux_store.jsx'; import store from 'stores/redux_store.jsx';
const getState = store.getState; const getState = store.getState;
const dispatch = store.dispatch;
import {searchChannels} from 'mattermost-redux/actions/channels'; import {Client4} from 'mattermost-redux/client';
import {autocompleteUsers} from 'mattermost-redux/actions/users';
import {getCurrentUserId, searchProfiles} from 'mattermost-redux/selectors/entities/users'; import {getCurrentUserId, searchProfiles} from 'mattermost-redux/selectors/entities/users';
import {getChannelsInCurrentTeam, getMyChannelMemberships, getGroupChannels} from 'mattermost-redux/selectors/entities/channels'; import {getChannelsInCurrentTeam, getMyChannelMemberships, getGroupChannels} from 'mattermost-redux/selectors/entities/channels';
@@ -124,17 +122,27 @@ export default class SwitchChannelProvider extends Provider {
} }
async fetchUsersAndChannels(channelPrefix, suggestionId) { async fetchUsersAndChannels(channelPrefix, suggestionId) {
const usersAsync = autocompleteUsers(channelPrefix)(dispatch, getState); const usersAsync = Client4.autocompleteUsers(channelPrefix, '', '');
const channelsAsync = searchChannels(getCurrentTeamId(getState()), channelPrefix)(dispatch, getState); const channelsAsync = Client4.searchChannels(getCurrentTeamId(getState()), channelPrefix);
await usersAsync;
await channelsAsync; let usersFromServer = [];
let channelsFromServer = [];
try {
usersFromServer = await usersAsync;
channelsFromServer = await channelsAsync;
} catch (err) {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_ERROR,
err
});
}
if (this.shouldCancelDispatch(channelPrefix)) { if (this.shouldCancelDispatch(channelPrefix)) {
return; return;
} }
const users = Object.assign([], searchProfiles(getState(), channelPrefix, true)); const users = Object.assign([], searchProfiles(getState(), channelPrefix, true), usersFromServer);
const channels = getChannelsInCurrentTeam(getState()).concat(getGroupChannels(getState())); const channels = getChannelsInCurrentTeam(getState()).concat(getGroupChannels(getState())).concat(channelsFromServer);
this.formatChannelsAndDispatch(channelPrefix, suggestionId, channels, users); this.formatChannelsAndDispatch(channelPrefix, suggestionId, channels, users);
} }
@@ -148,8 +156,15 @@ export default class SwitchChannelProvider extends Provider {
const currentId = getCurrentUserId(getState()); const currentId = getCurrentUserId(getState());
const completedChannels = {};
for (const id of Object.keys(allChannels)) { for (const id of Object.keys(allChannels)) {
const channel = allChannels[id]; const channel = allChannels[id];
if (completedChannels[channel.id]) {
continue;
}
const member = members[channel.id]; const member = members[channel.id];
if (channel.display_name.toLowerCase().indexOf(channelPrefix.toLowerCase()) !== -1) { if (channel.display_name.toLowerCase().indexOf(channelPrefix.toLowerCase()) !== -1) {
@@ -171,17 +186,23 @@ export default class SwitchChannelProvider extends Provider {
wrappedChannel.type = Constants.MENTION_CHANNELS; wrappedChannel.type = Constants.MENTION_CHANNELS;
} else { } else {
wrappedChannel.type = Constants.MENTION_MORE_CHANNELS; wrappedChannel.type = Constants.MENTION_MORE_CHANNELS;
if (skipNotInChannel || !newChannel.display_name.startsWith(channelPrefix)) { if (skipNotInChannel || !newChannel.display_name.toLowerCase().startsWith(channelPrefix)) {
continue; continue;
} }
} }
completedChannels[channel.id] = true;
channels.push(wrappedChannel); channels.push(wrappedChannel);
} }
} }
for (let i = 0; i < users.length; i++) { for (let i = 0; i < users.length; i++) {
const user = users[i]; const user = users[i];
if (completedChannels[user.id]) {
continue;
}
const isDMVisible = getBool(getState(), Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, user.id, false); const isDMVisible = getBool(getState(), Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, user.id, false);
let displayName = `@${user.username} `; let displayName = `@${user.username} `;
@@ -217,6 +238,7 @@ export default class SwitchChannelProvider extends Provider {
} }
} }
completedChannels[user.id] = true;
channels.push(wrappedChannel); channels.push(wrappedChannel);
} }