From e56f172f9abcfc09bb950aeca6ebbac4ae25e58a Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Fri, 10 Jun 2022 13:00:50 -0400 Subject: [PATCH] Fetch missing GM display name (#6374) --- app/actions/remote/channel.ts | 14 ++++++++++++-- app/actions/remote/user.ts | 13 ++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/actions/remote/channel.ts b/app/actions/remote/channel.ts index b66c372fe..9d6d28101 100644 --- a/app/actions/remote/channel.ts +++ b/app/actions/remote/channel.ts @@ -13,7 +13,7 @@ import DatabaseManager from '@database/manager'; import {privateChannelJoinPrompt} from '@helpers/api/channel'; import {getTeammateNameDisplaySetting} from '@helpers/api/preference'; import NetworkManager from '@managers/network_manager'; -import {prepareMyChannelsForTeam, getChannelById, getChannelByName, getMyChannel, getChannelInfo, queryMyChannelSettingsByIds} from '@queries/servers/channel'; +import {prepareMyChannelsForTeam, getChannelById, getChannelByName, getMyChannel, getChannelInfo, queryMyChannelSettingsByIds, getMembersCountByChannelsId} from '@queries/servers/channel'; import {queryPreferencesByCategoryAndName} from '@queries/servers/preference'; import {getCommonSystemValues, getConfig, getCurrentTeamId, getCurrentUserId, getLicense, setCurrentChannelId} from '@queries/servers/system'; import {prepareMyTeams, getNthLastChannelFromTeam, getMyTeamById, getTeamById, getTeamByName, queryMyTeams} from '@queries/servers/team'; @@ -438,10 +438,16 @@ export async function fetchMissingDirectChannelsInfo(serverUrl: string, directCh const updatedChannels = new Set(); const dms: Channel[] = []; + const dmIds: string[] = []; + const dmWithoutDisplayName = new Set(); const gms: Channel[] = []; for (const c of directChannels) { if (c.type === General.DM_CHANNEL) { dms.push(c); + dmIds.push(c.id); + if (!c.display_name) { + dmWithoutDisplayName.add(c.id); + } continue; } gms.push(c); @@ -449,8 +455,12 @@ export async function fetchMissingDirectChannelsInfo(serverUrl: string, directCh try { const currentUser = await getCurrentUser(database); + + // let's filter those channels that we already have the users + const membersCount = await getMembersCountByChannelsId(database, dmIds); + const profileChannelsToFetch = dmIds.filter((id) => membersCount[id] <= 1 || dmWithoutDisplayName.has(id)); const results = await Promise.all([ - fetchProfilesPerChannels(serverUrl, dms.map((c) => c.id), currentUserId, false), + profileChannelsToFetch.length ? fetchProfilesPerChannels(serverUrl, profileChannelsToFetch, currentUserId, false) : Promise.resolve({data: undefined}), fetchProfilesInGroupChannels(serverUrl, gms.map((c) => c.id), false), ]); diff --git a/app/actions/remote/user.ts b/app/actions/remote/user.ts index bf7fb823b..18cc2aed5 100644 --- a/app/actions/remote/user.ts +++ b/app/actions/remote/user.ts @@ -190,17 +190,8 @@ export async function fetchProfilesPerChannels(serverUrl: string, channelIds: st return {error: `${serverUrl} database not found`}; } - const {database} = operator; - - // let's filter those channels that we already have the users - const membersCount = await getMembersCountByChannelsId(database, channelIds); - const channelsToFetch = channelIds.filter((c) => membersCount[c] <= 1); - if (!channelsToFetch.length) { - return {data: []}; - } - - // Batch fetching profiles per channel by chunks of 300 - const channels = chunk(channelsToFetch, 300); + // Batch fetching profiles per channel by chunks of 250 + const channels = chunk(channelIds, 250); const data: ProfilesInChannelRequest[] = []; for await (const cIds of channels) {