[MM-56904] Reduce the number of api requests made to fetch user information for GMs on page load (#27149)
* use new endpoint to fetch group members
Этот коммит содержится в:
@@ -520,11 +520,8 @@ describe('Actions.User', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Should call p-queue APIs on loadProfilesForGM', async () => {
|
||||
test('Should call getProfilesInGroupChannels on loadProfilesForGM', async () => {
|
||||
const gmChannel = {id: 'gmChannel', type: General.GM_CHANNEL, team_id: '', delete_at: 0};
|
||||
UserActions.queue.add = jest.fn().mockReturnValue(jest.fn());
|
||||
UserActions.queue.onEmpty = jest.fn();
|
||||
|
||||
const user = TestHelper.fakeUser();
|
||||
|
||||
const profiles = {
|
||||
@@ -555,7 +552,7 @@ describe('Actions.User', () => {
|
||||
profiles,
|
||||
statuses: {},
|
||||
profilesInChannel: {
|
||||
[gmChannel.id]: new Set(['current_user_id']),
|
||||
[gmChannel.id]: new Set([]),
|
||||
},
|
||||
},
|
||||
teams: {
|
||||
@@ -605,9 +602,10 @@ describe('Actions.User', () => {
|
||||
|
||||
const testStore = mockStore(state);
|
||||
store.getState.mockImplementation(testStore.getState);
|
||||
store.dispatch.mockImplementation(testStore.dispatch);
|
||||
const actions = testStore.getActions();
|
||||
|
||||
await UserActions.loadProfilesForGM();
|
||||
expect(UserActions.queue.onEmpty).toHaveBeenCalled();
|
||||
expect(UserActions.queue.add).toHaveBeenCalled();
|
||||
expect(actions).toEqual([{args: [['gmChannel']], type: 'MOCK_GET_PROFILES_IN_GROUP_CHANNELS'}]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import PQueue from 'p-queue';
|
||||
|
||||
import type {UserAutocomplete} from '@mattermost/types/autocomplete';
|
||||
import type {Channel} from '@mattermost/types/channels';
|
||||
import type {UserProfile, UserStatus} from '@mattermost/types/users';
|
||||
@@ -37,7 +35,6 @@ import * as Utils from 'utils/utils';
|
||||
|
||||
import type {GlobalState} from 'types/store';
|
||||
|
||||
export const queue = new PQueue({concurrency: 4});
|
||||
const dispatch = store.dispatch;
|
||||
const getState = store.getState;
|
||||
|
||||
@@ -312,9 +309,9 @@ export async function loadProfilesForGM() {
|
||||
const collapsedThreads = isCollapsedThreadsEnabled(state);
|
||||
|
||||
const userIdsForLoadingCustomEmojis = new Set();
|
||||
const channelUsersToLoad: string[] = [];
|
||||
for (const channel of getGMsForLoading(state)) {
|
||||
const userIds = userIdsInChannels[channel.id] || new Set();
|
||||
|
||||
userIds.forEach((userId) => userIdsForLoadingCustomEmojis.add(userId));
|
||||
|
||||
if (userIds.size >= Constants.MIN_USERS_IN_GM) {
|
||||
@@ -340,12 +337,14 @@ export async function loadProfilesForGM() {
|
||||
value: 'true',
|
||||
});
|
||||
}
|
||||
|
||||
const getProfilesAction = UserActions.getProfilesInChannel(channel.id, 0, Constants.MAX_USERS_IN_GM);
|
||||
queue.add(() => dispatch(getProfilesAction));
|
||||
if (userIds.size === 0) {
|
||||
channelUsersToLoad.push(channel.id);
|
||||
}
|
||||
}
|
||||
|
||||
await queue.onEmpty();
|
||||
if (channelUsersToLoad.length > 0) {
|
||||
await dispatch(UserActions.getProfilesInGroupChannels(channelUsersToLoad));
|
||||
}
|
||||
|
||||
if (userIdsForLoadingCustomEmojis.size > 0) {
|
||||
dispatch(loadCustomEmojisForCustomStatusesByUserIds(userIdsForLoadingCustomEmojis));
|
||||
|
||||
@@ -102,17 +102,6 @@ exports[`components/sidebar/sidebar_category/sidebar_category_sorting_menu shoul
|
||||
</React.Fragment>
|
||||
}
|
||||
>
|
||||
<MenuItem
|
||||
id="showAllDms-category_id"
|
||||
labels={
|
||||
<Memo(MemoizedFormattedMessage)
|
||||
defaultMessage="All direct messages"
|
||||
id="sidebar.allDirectMessages"
|
||||
/>
|
||||
}
|
||||
onClick={[Function]}
|
||||
/>
|
||||
<MenuItemSeparator />
|
||||
<MenuItem
|
||||
id="showDmCount-category_id-10"
|
||||
key="showDmCount-category_id-10"
|
||||
|
||||
@@ -147,17 +147,6 @@ const SidebarCategorySortingMenu = ({
|
||||
)}
|
||||
menuId={`showMessagesCount-${category.id}-menu`}
|
||||
>
|
||||
<Menu.Item
|
||||
id={`showAllDms-${category.id}`}
|
||||
labels={(
|
||||
<FormattedMessage
|
||||
id='sidebar.allDirectMessages'
|
||||
defaultMessage='All direct messages'
|
||||
/>
|
||||
)}
|
||||
onClick={() => handlelimitVisibleDMsGMs(Constants.HIGHEST_DM_SHOW_COUNT)}
|
||||
/>
|
||||
<Menu.Separator/>
|
||||
{Constants.DM_AND_GM_SHOW_COUNTS.map((dmGmShowCount) => (
|
||||
<Menu.Item
|
||||
id={`showDmCount-${category.id}-${dmGmShowCount}`}
|
||||
|
||||
@@ -16,8 +16,6 @@ import SettingItemMax from 'components/setting_item_max';
|
||||
import SettingItemMin from 'components/setting_item_min';
|
||||
import type SettingItemMinComponent from 'components/setting_item_min';
|
||||
|
||||
import {localizeMessage} from 'utils/utils';
|
||||
|
||||
type Limit = {
|
||||
value: number;
|
||||
label: string;
|
||||
@@ -44,7 +42,6 @@ type State = {
|
||||
}
|
||||
|
||||
const limits: Limit[] = [
|
||||
{value: 10000, label: localizeMessage('user.settings.sidebar.limitVisibleGMsDMs.allDirectMessages', 'All Direct Messages')},
|
||||
{value: 10, label: '10'},
|
||||
{value: 15, label: '15'},
|
||||
{value: 20, label: '20'},
|
||||
|
||||
@@ -4972,7 +4972,6 @@
|
||||
"sidebar_right_menu.console": "System Console",
|
||||
"sidebar_right_menu.flagged": "Saved messages",
|
||||
"sidebar_right_menu.recentMentions": "Recent Mentions",
|
||||
"sidebar.allDirectMessages": "All direct messages",
|
||||
"sidebar.createDirectMessage": "Write a direct message",
|
||||
"sidebar.createUserGroup": "Create New User Group",
|
||||
"sidebar.directchannel.you": "{displayname} (you)",
|
||||
@@ -5663,7 +5662,6 @@
|
||||
"user.settings.security.viewHistory": "View Access History",
|
||||
"user.settings.security.viewHistory.icon": "Access History Icon",
|
||||
"user.settings.sidebar.icon": "Sidebar Settings Icon",
|
||||
"user.settings.sidebar.limitVisibleGMsDMs.allDirectMessages": "All Direct Messages",
|
||||
"user.settings.sidebar.limitVisibleGMsDMsDesc": "You can also change these settings in the direct messages sidebar menu.",
|
||||
"user.settings.sidebar.limitVisibleGMsDMsTitle": "Number of direct messages to show",
|
||||
"user.settings.sidebar.off": "Off",
|
||||
|
||||
Ссылка в новой задаче
Block a user