mirror of
https://github.com/mattermost/mattermost.git
synced 2026-08-13 06:24:52 -05:00
MM52237 - prevent fetching fileCount from unnecessary places (#23981)
* MM52237 - prevent call file count from unnecesary places * rename the variable to make more clear function signature
This commit is contained in:
@@ -65,7 +65,7 @@ export function emitChannelClickEvent(channel: Channel) {
|
||||
const currentChannelId = getCurrentChannelId(state);
|
||||
const previousRhsState = getPreviousRhsState(state);
|
||||
|
||||
dispatch(getChannelStats(chan.id, true));
|
||||
dispatch(getChannelStats(chan.id));
|
||||
|
||||
const penultimate = LocalStorageStore.getPreviousChannelName(userId, teamId);
|
||||
const penultimateType = LocalStorageStore.getPreviousViewedType(userId, teamId);
|
||||
|
||||
@@ -99,7 +99,7 @@ interface MenuProps {
|
||||
showChannelFiles: (channelId: string) => void;
|
||||
showPinnedPosts: (channelId: string | undefined) => void;
|
||||
showChannelMembers: (channelId: string) => void;
|
||||
getChannelStats: (channelId: string) => Promise<{data: ChannelStats}>;
|
||||
getChannelStats: (channelId: string, includeFileCount: boolean) => Promise<{data: ChannelStats}>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ const Menu = ({channel, channelStats, isArchived, className, actions}: MenuProps
|
||||
const fileCount = channelStats?.files_count >= 0 ? channelStats?.files_count : 0;
|
||||
|
||||
useEffect(() => {
|
||||
actions.getChannelStats(channel.id).then(() => {
|
||||
actions.getChannelStats(channel.id, true).then(() => {
|
||||
setLoadingStats(false);
|
||||
});
|
||||
return () => {
|
||||
|
||||
@@ -1937,7 +1937,7 @@ describe('Actions.Channels', () => {
|
||||
|
||||
it('getChannelStats', async () => {
|
||||
nock(Client4.getBaseRoute()).
|
||||
get(`/channels/${TestHelper.basicChannel!.id}/stats`).
|
||||
get(`/channels/${TestHelper.basicChannel!.id}/stats?exclude_files_count=true`).
|
||||
reply(200, {channel_id: TestHelper.basicChannel!.id, member_count: 1});
|
||||
|
||||
await store.dispatch(Actions.getChannelStats(TestHelper.basicChannel!.id));
|
||||
@@ -1970,7 +1970,7 @@ describe('Actions.Channels', () => {
|
||||
await store.dispatch(Actions.joinChannel(TestHelper.basicUser!.id, TestHelper.basicTeam!.id, channelId));
|
||||
|
||||
nock(Client4.getBaseRoute()).
|
||||
get(`/channels/${TestHelper.basicChannel!.id}/stats`).
|
||||
get(`/channels/${TestHelper.basicChannel!.id}/stats?exclude_files_count=true`).
|
||||
reply(200, {channel_id: TestHelper.basicChannel!.id, member_count: 1});
|
||||
|
||||
await store.dispatch(Actions.getChannelStats(channelId));
|
||||
@@ -2041,7 +2041,7 @@ describe('Actions.Channels', () => {
|
||||
await store.dispatch(Actions.joinChannel(TestHelper.basicUser!.id, TestHelper.basicTeam!.id, channelId));
|
||||
|
||||
nock(Client4.getBaseRoute()).
|
||||
get(`/channels/${TestHelper.basicChannel!.id}/stats`).
|
||||
get(`/channels/${TestHelper.basicChannel!.id}/stats?exclude_files_count=true`).
|
||||
reply(200, {channel_id: TestHelper.basicChannel!.id, member_count: 1});
|
||||
|
||||
await store.dispatch(Actions.getChannelStats(channelId));
|
||||
|
||||
@@ -1063,11 +1063,11 @@ export function searchGroupChannels(term: string): ActionFunc {
|
||||
});
|
||||
}
|
||||
|
||||
export function getChannelStats(channelId: string, excludeFilesCount?: boolean): ActionFunc {
|
||||
export function getChannelStats(channelId: string, includeFileCount?: boolean): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
let stat;
|
||||
try {
|
||||
stat = await Client4.getChannelStats(channelId, excludeFilesCount);
|
||||
stat = await Client4.getChannelStats(channelId, includeFileCount);
|
||||
} catch (error) {
|
||||
forceLogoutIfNecessary(error, dispatch, getState);
|
||||
dispatch(logError(error));
|
||||
|
||||
@@ -1118,7 +1118,7 @@ describe('Actions.Posts', () => {
|
||||
const {dispatch, getState} = store;
|
||||
|
||||
nock(Client4.getBaseRoute()).
|
||||
get(`/channels/${TestHelper.basicChannel!.id}/stats`).
|
||||
get(`/channels/${TestHelper.basicChannel!.id}/stats?exclude_files_count=true`).
|
||||
reply(200, {channel_id: TestHelper.basicChannel!.id, member_count: 1, pinnedpost_count: 0});
|
||||
|
||||
await dispatch(getChannelStats(TestHelper.basicChannel!.id));
|
||||
@@ -1157,7 +1157,7 @@ describe('Actions.Posts', () => {
|
||||
const {dispatch, getState} = store;
|
||||
|
||||
nock(Client4.getBaseRoute()).
|
||||
get(`/channels/${TestHelper.basicChannel!.id}/stats`).
|
||||
get(`/channels/${TestHelper.basicChannel!.id}/stats?exclude_files_count=true`).
|
||||
reply(200, {channel_id: TestHelper.basicChannel!.id, member_count: 1, pinnedpost_count: 0});
|
||||
|
||||
await dispatch(getChannelStats(TestHelper.basicChannel!.id));
|
||||
|
||||
@@ -1739,8 +1739,8 @@ export default class Client4 {
|
||||
);
|
||||
};
|
||||
|
||||
getChannelStats = (channelId: string, excludeFilesCount = false) => {
|
||||
const param = excludeFilesCount ? `?exclude_files_count=${excludeFilesCount}` : '';
|
||||
getChannelStats = (channelId: string, includeFileCount = false) => {
|
||||
const param = !includeFileCount ? '?exclude_files_count=true' : '';
|
||||
return this.doFetch<ChannelStats>(
|
||||
`${this.getChannelRoute(channelId)}/stats${param}`,
|
||||
{method: 'get'},
|
||||
|
||||
Reference in New Issue
Block a user