From 59a49b3972ab414cd921fa7703dc18d0e5e20b03 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Mon, 18 Nov 2024 17:49:44 +0800 Subject: [PATCH] fix entry logic to not re-fetch data for the initial team (#8349) --- app/actions/remote/entry/common.ts | 10 +++++++++- app/actions/remote/thread.ts | 10 ++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/actions/remote/entry/common.ts b/app/actions/remote/entry/common.ts index c9c1ab2142d..8a68e7e6be7 100644 --- a/app/actions/remote/entry/common.ts +++ b/app/actions/remote/entry/common.ts @@ -396,6 +396,11 @@ async function restDeferredAppEntryActions( const sortedTeamIds = new Set(teamsOrder?.value.split(',')); const membershipSet = new Set(teamData.memberships.map((m) => m.team_id)); const teamMap = new Map(teamData.teams.map((t) => [t.id, t])); + if (initialTeamId) { + sortedTeamIds.delete(initialTeamId); + membershipSet.delete(initialTeamId); + teamMap.delete(initialTeamId); + } let myTeams: Team[]; if (sortedTeamIds.size) { @@ -411,7 +416,10 @@ async function restDeferredAppEntryActions( myTeams = teamData.teams. sort((a, b) => a.display_name.toLocaleLowerCase().localeCompare(b.display_name.toLocaleLowerCase())); } - fetchTeamsChannelsThreadsAndUnreadPosts(serverUrl, since, myTeams, isCRTEnabled); + + if (myTeams.length) { + fetchTeamsChannelsThreadsAndUnreadPosts(serverUrl, since, myTeams, isCRTEnabled); + } } }); diff --git a/app/actions/remote/thread.ts b/app/actions/remote/thread.ts index a6b6534c187..0549c6ae1de 100644 --- a/app/actions/remote/thread.ts +++ b/app/actions/remote/thread.ts @@ -14,7 +14,6 @@ import {getConfigValue, getCurrentChannelId, getCurrentTeamId} from '@queries/se import {getIsCRTEnabled, getThreadById, getTeamThreadsSyncData} from '@queries/servers/thread'; import {getCurrentUser} from '@queries/servers/user'; import {getFullErrorMessage} from '@utils/errors'; -import {isMinimumServerVersion} from '@utils/helpers'; import {logDebug, logError} from '@utils/log'; import {showThreadFollowingSnackbar} from '@utils/snack_bar'; import {getThreadsListEdges} from '@utils/thread'; @@ -286,15 +285,10 @@ export const syncThreadsIfNeeded = async (serverUrl: string, isCRTEnabled: boole return {models: []}; } - const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl); + const {operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl); const promises = []; const models: Model[][] = []; - // this is to keep backwards compatibility with servers that send the - // threads for DM / GM regardless for every team - const version = await getConfigValue(database, 'Version'); - const hasThreadExclusions = isMinimumServerVersion(version, 10, 2, 0); - if (teams?.length) { for (const team of teams) { promises.push(syncTeamThreads(serverUrl, team.id, true, true)); @@ -312,7 +306,7 @@ export const syncThreadsIfNeeded = async (serverUrl: string, isCRTEnabled: boole const flat = models.flat(); if (!fetchOnly && flat.length) { - const uniqueArray = hasThreadExclusions ? flat : removeDuplicatesModels(flat); + const uniqueArray = removeDuplicatesModels(flat); await operator.batchRecords(uniqueArray, 'syncThreadsIfNeeded'); }