-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request metrics improvements #8420
Open
enahum
wants to merge
14
commits into
main
Choose a base branch
from
request-metrics-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,777
−876
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
41b32a6
Network metrics
enahum 74d3b8c
update network-client ref
enahum 112578c
fix unit tests
enahum 0951b33
missing catch error parsing
enahum dbdac89
Replace API's to fetch all teams and channels for a user
enahum a5d8bb2
update network library and fix tests
enahum 9f65e90
Merge branch 'main' into request-metrics-improvements
rahimrahman 02e41da
feat(MM-61865): send network request telemetry data to the server (#8…
rahimrahman 6506ce8
fix: improve parallel requests calculation (#8439)
rahimrahman 1ddf677
resolveAndFlattenModels with a capital F
rahimrahman b448540
Merge branch 'main' into request-metrics-improvements
mattermost-build 641f0ca
add try..catch within resolveAndFlattenModels
rahimrahman d1b73a2
update groupLabel to fix failing lint
rahimrahman f8c0c76
fix linting issue due to unknown group label
rahimrahman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import {DeviceEventEmitter} from 'react-native'; | ||
|
||
import {addChannelToDefaultCategory, handleConvertedGMCategories, storeCategories} from '@actions/local/category'; | ||
import {markChannelAsViewed, removeCurrentUserFromChannel, setChannelDeleteAt, storeMyChannelsForTeam, switchToChannel} from '@actions/local/channel'; | ||
import {markChannelAsViewed, removeCurrentUserFromChannel, setChannelDeleteAt, storeAllMyChannels, storeMyChannelsForTeam, switchToChannel} from '@actions/local/channel'; | ||
import {switchToGlobalThreads} from '@actions/local/thread'; | ||
import {loadCallForChannel} from '@calls/actions/calls'; | ||
import {DeepLink, Events, General, Preferences, Screens} from '@constants'; | ||
|
@@ -376,7 +376,7 @@ export async function fetchChannelCreator(serverUrl: string, channelId: string, | |
} | ||
} | ||
|
||
export async function fetchChannelStats(serverUrl: string, channelId: string, fetchOnly = false, groupLabel?: string) { | ||
export async function fetchChannelStats(serverUrl: string, channelId: string, fetchOnly = false, groupLabel?: RequestGroupLabel) { | ||
try { | ||
const client = NetworkManager.getClient(serverUrl); | ||
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl); | ||
|
@@ -404,10 +404,74 @@ export async function fetchChannelStats(serverUrl: string, channelId: string, fe | |
} | ||
} | ||
|
||
export async function fetchAllMyChannelsForAllTeams(serverUrl: string, since: number, isCRTEnabled: boolean, fetchOnly = false, groupLabel?: RequestGroupLabel) { | ||
try { | ||
if (!fetchOnly) { | ||
setTeamLoading(serverUrl, true); | ||
} | ||
const client = NetworkManager.getClient(serverUrl); | ||
const {operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl); | ||
const promises: [Promise<Channel[]>, Promise<ChannelMembership[]>] = [ | ||
client.getAllChannelsFromAllTeams(since, since > 0, groupLabel), | ||
client.getAllMyChannelMembersFromAllTeams(0, General.CHANNEL_MEMBERS_CHUNK_SIZE, groupLabel), | ||
]; | ||
|
||
const [channels, memberships] = await Promise.all(promises); | ||
const remaining = Math.floor(channels.length / General.CHANNEL_MEMBERS_CHUNK_SIZE); | ||
const remainingMembershipsPromises = []; | ||
const categoriesPromises = []; | ||
|
||
const teamIdsSet = channels.reduce<Set<string>>((set, c) => { | ||
if (c.team_id) { | ||
set.add(c.team_id); | ||
} | ||
return set; | ||
}, new Set()); | ||
for (const teamId of teamIdsSet) { | ||
categoriesPromises.push(client.getCategories('me', teamId, groupLabel)); | ||
} | ||
|
||
if (remaining > 0) { | ||
for (let i = 1; i <= remaining; i++) { | ||
remainingMembershipsPromises.push(client.getAllMyChannelMembersFromAllTeams(i, General.CHANNEL_MEMBERS_CHUNK_SIZE, groupLabel)); | ||
} | ||
Comment on lines
+435
to
+437
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This for loop adds to the problem in my previous comment. |
||
} | ||
|
||
const results = await Promise.all([...remainingMembershipsPromises, ...categoriesPromises]); | ||
const categories: CategoryWithChannels[] = []; | ||
for (const result of results) { | ||
if (Array.isArray(result)) { | ||
memberships.push(...result); | ||
} else if ('categories' in result) { | ||
categories.push(...result.categories); | ||
} | ||
} | ||
|
||
if (!fetchOnly) { | ||
const {models: chModels} = await storeAllMyChannels(serverUrl, channels, memberships, isCRTEnabled, true); | ||
const {models: catModels} = await storeCategories(serverUrl, categories, true, true); // Re-sync | ||
const models = (chModels || []).concat(catModels || []); | ||
if (models.length) { | ||
await operator.batchRecords(models, 'fetchAllMyChannelsForAllTeams'); | ||
} | ||
setTeamLoading(serverUrl, false); | ||
} | ||
|
||
return {channels, memberships, categories}; | ||
} catch (error) { | ||
logDebug('error on fetchMyChannelsForTeam', getFullErrorMessage(error)); | ||
if (!fetchOnly) { | ||
setTeamLoading(serverUrl, false); | ||
} | ||
forceLogoutIfNecessary(serverUrl, error); | ||
return {error}; | ||
} | ||
} | ||
|
||
export async function fetchMyChannelsForTeam( | ||
serverUrl: string, teamId: string, includeDeleted = true, | ||
since = 0, fetchOnly = false, excludeDirect = false, | ||
isCRTEnabled?: boolean, groupLabel?: string, | ||
isCRTEnabled?: boolean, groupLabel?: RequestGroupLabel, | ||
): Promise<MyChannelsRequest> { | ||
try { | ||
if (!fetchOnly) { | ||
|
@@ -457,7 +521,7 @@ export async function fetchMyChannelsForTeam( | |
} | ||
} | ||
|
||
export async function fetchMyChannel(serverUrl: string, teamId: string, channelId: string, fetchOnly = false, groupLabel?: string): Promise<MyChannelsRequest> { | ||
export async function fetchMyChannel(serverUrl: string, teamId: string, channelId: string, fetchOnly = false, groupLabel?: RequestGroupLabel): Promise<MyChannelsRequest> { | ||
try { | ||
const client = NetworkManager.getClient(serverUrl); | ||
|
||
|
@@ -484,7 +548,7 @@ export async function fetchMyChannel(serverUrl: string, teamId: string, channelI | |
export async function fetchMissingDirectChannelsInfo( | ||
serverUrl: string, directChannels: Channel[], locale?: string, | ||
teammateDisplayNameSetting?: string, currentUserId?: string, | ||
fetchOnly = false, groupLabel?: string, | ||
fetchOnly = false, groupLabel?: RequestGroupLabel, | ||
) { | ||
try { | ||
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl); | ||
|
@@ -662,7 +726,7 @@ export async function joinChannelIfNeeded(serverUrl: string, channelId: string) | |
} | ||
} | ||
|
||
export async function markChannelAsRead(serverUrl: string, channelId: string, updateLocal = false, groupLabel?: string) { | ||
export async function markChannelAsRead(serverUrl: string, channelId: string, updateLocal = false, groupLabel?: RequestGroupLabel) { | ||
try { | ||
const client = NetworkManager.getClient(serverUrl); | ||
await client.viewMyChannel(channelId, undefined, groupLabel); | ||
|
@@ -1047,7 +1111,7 @@ export async function getChannelTimezones(serverUrl: string, channelId: string) | |
} | ||
} | ||
|
||
export async function switchToChannelById(serverUrl: string, channelId: string, teamId?: string, skipLastUnread = false, groupLabel?: string) { | ||
export async function switchToChannelById(serverUrl: string, channelId: string, teamId?: string, skipLastUnread = false, groupLabel?: RequestGroupLabel) { | ||
if (channelId === Screens.GLOBAL_THREADS) { | ||
return switchToGlobalThreads(serverUrl, teamId); | ||
} | ||
|
@@ -1059,7 +1123,7 @@ export async function switchToChannelById(serverUrl: string, channelId: string, | |
|
||
DeviceEventEmitter.emit(Events.CHANNEL_SWITCH, true); | ||
|
||
fetchPostsForChannel(serverUrl, channelId, false, groupLabel); | ||
fetchPostsForChannel(serverUrl, channelId, false, false, groupLabel); | ||
fetchChannelBookmarks(serverUrl, channelId, false, groupLabel); | ||
await switchToChannel(serverUrl, channelId, teamId, skipLastUnread); | ||
openChannelIfNeeded(serverUrl, channelId, groupLabel); | ||
|
@@ -1258,8 +1322,10 @@ export const handleKickFromChannel = async (serverUrl: string, channelId: string | |
const currentServer = await getActiveServer(); | ||
if (currentServer?.url === serverUrl) { | ||
const channel = await getChannelById(database, channelId); | ||
DeviceEventEmitter.emit(event, channel?.displayName); | ||
await dismissAllModalsAndPopToRoot(); | ||
if (channel) { | ||
DeviceEventEmitter.emit(event, channel.displayName); | ||
await dismissAllModalsAndPopToRoot(); | ||
} | ||
} | ||
|
||
const tabletDevice = isTablet(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have an absurd amount of teams, we are flooding the network layer with get categories calls. It is not common, but we have already had reports of people having 100+ teams.
Unless we create a priority queue down at the network layer, we may want to consider batching this, so other processes can access the network layer before this finishes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Thanks for your observation. This is something this PR/changes is trying to establish on where the bottlenecks are and learn from it. And prioritize all the issues. We have a long way to go, but first, data.