Skip to content

Commit

Permalink
fix entry logic to not re-fetch data for the initial team (#8349)
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum authored Nov 18, 2024
1 parent 97788aa commit 59a49b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 9 additions & 1 deletion app/actions/remote/entry/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
});

Expand Down
10 changes: 2 additions & 8 deletions app/actions/remote/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
Expand All @@ -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');
}

Expand Down

0 comments on commit 59a49b3

Please sign in to comment.