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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
93b7957de3
Коммит
525c21a9d3
@@ -65,7 +65,7 @@ export function emitChannelClickEvent(channel: Channel) {
|
|||||||
const currentChannelId = getCurrentChannelId(state);
|
const currentChannelId = getCurrentChannelId(state);
|
||||||
const previousRhsState = getPreviousRhsState(state);
|
const previousRhsState = getPreviousRhsState(state);
|
||||||
|
|
||||||
dispatch(getChannelStats(chan.id, true));
|
dispatch(getChannelStats(chan.id));
|
||||||
|
|
||||||
const penultimate = LocalStorageStore.getPreviousChannelName(userId, teamId);
|
const penultimate = LocalStorageStore.getPreviousChannelName(userId, teamId);
|
||||||
const penultimateType = LocalStorageStore.getPreviousViewedType(userId, teamId);
|
const penultimateType = LocalStorageStore.getPreviousViewedType(userId, teamId);
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ interface MenuProps {
|
|||||||
showChannelFiles: (channelId: string) => void;
|
showChannelFiles: (channelId: string) => void;
|
||||||
showPinnedPosts: (channelId: string | undefined) => void;
|
showPinnedPosts: (channelId: string | undefined) => void;
|
||||||
showChannelMembers: (channelId: string) => 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;
|
const fileCount = channelStats?.files_count >= 0 ? channelStats?.files_count : 0;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
actions.getChannelStats(channel.id).then(() => {
|
actions.getChannelStats(channel.id, true).then(() => {
|
||||||
setLoadingStats(false);
|
setLoadingStats(false);
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
@@ -1937,7 +1937,7 @@ describe('Actions.Channels', () => {
|
|||||||
|
|
||||||
it('getChannelStats', async () => {
|
it('getChannelStats', async () => {
|
||||||
nock(Client4.getBaseRoute()).
|
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});
|
reply(200, {channel_id: TestHelper.basicChannel!.id, member_count: 1});
|
||||||
|
|
||||||
await store.dispatch(Actions.getChannelStats(TestHelper.basicChannel!.id));
|
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));
|
await store.dispatch(Actions.joinChannel(TestHelper.basicUser!.id, TestHelper.basicTeam!.id, channelId));
|
||||||
|
|
||||||
nock(Client4.getBaseRoute()).
|
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});
|
reply(200, {channel_id: TestHelper.basicChannel!.id, member_count: 1});
|
||||||
|
|
||||||
await store.dispatch(Actions.getChannelStats(channelId));
|
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));
|
await store.dispatch(Actions.joinChannel(TestHelper.basicUser!.id, TestHelper.basicTeam!.id, channelId));
|
||||||
|
|
||||||
nock(Client4.getBaseRoute()).
|
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});
|
reply(200, {channel_id: TestHelper.basicChannel!.id, member_count: 1});
|
||||||
|
|
||||||
await store.dispatch(Actions.getChannelStats(channelId));
|
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) => {
|
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||||
let stat;
|
let stat;
|
||||||
try {
|
try {
|
||||||
stat = await Client4.getChannelStats(channelId, excludeFilesCount);
|
stat = await Client4.getChannelStats(channelId, includeFileCount);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
forceLogoutIfNecessary(error, dispatch, getState);
|
forceLogoutIfNecessary(error, dispatch, getState);
|
||||||
dispatch(logError(error));
|
dispatch(logError(error));
|
||||||
|
|||||||
@@ -1118,7 +1118,7 @@ describe('Actions.Posts', () => {
|
|||||||
const {dispatch, getState} = store;
|
const {dispatch, getState} = store;
|
||||||
|
|
||||||
nock(Client4.getBaseRoute()).
|
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});
|
reply(200, {channel_id: TestHelper.basicChannel!.id, member_count: 1, pinnedpost_count: 0});
|
||||||
|
|
||||||
await dispatch(getChannelStats(TestHelper.basicChannel!.id));
|
await dispatch(getChannelStats(TestHelper.basicChannel!.id));
|
||||||
@@ -1157,7 +1157,7 @@ describe('Actions.Posts', () => {
|
|||||||
const {dispatch, getState} = store;
|
const {dispatch, getState} = store;
|
||||||
|
|
||||||
nock(Client4.getBaseRoute()).
|
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});
|
reply(200, {channel_id: TestHelper.basicChannel!.id, member_count: 1, pinnedpost_count: 0});
|
||||||
|
|
||||||
await dispatch(getChannelStats(TestHelper.basicChannel!.id));
|
await dispatch(getChannelStats(TestHelper.basicChannel!.id));
|
||||||
|
|||||||
@@ -1739,8 +1739,8 @@ export default class Client4 {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
getChannelStats = (channelId: string, excludeFilesCount = false) => {
|
getChannelStats = (channelId: string, includeFileCount = false) => {
|
||||||
const param = excludeFilesCount ? `?exclude_files_count=${excludeFilesCount}` : '';
|
const param = !includeFileCount ? '?exclude_files_count=true' : '';
|
||||||
return this.doFetch<ChannelStats>(
|
return this.doFetch<ChannelStats>(
|
||||||
`${this.getChannelRoute(channelId)}/stats${param}`,
|
`${this.getChannelRoute(channelId)}/stats${param}`,
|
||||||
{method: 'get'},
|
{method: 'get'},
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user