From c5b8d613f9b58355a5634eb6b2dce156b7060932 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Mon, 28 Feb 2022 16:39:26 -0300 Subject: [PATCH] Batch categories and channels in fetchMyChannelsForTeam action (#6010) --- app/actions/remote/channel.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/actions/remote/channel.ts b/app/actions/remote/channel.ts index 0603edeb7..290001f17 100644 --- a/app/actions/remote/channel.ts +++ b/app/actions/remote/channel.ts @@ -189,6 +189,11 @@ export const fetchChannelStats = async (serverUrl: string, channelId: string, fe }; export const fetchMyChannelsForTeam = async (serverUrl: string, teamId: string, includeDeleted = true, since = 0, fetchOnly = false, excludeDirect = false): Promise => { + const operator = DatabaseManager.serverDatabases[serverUrl]?.operator; + if (!operator) { + return {error: `${serverUrl} database not found`}; + } + let client: Client; try { client = NetworkManager.getClient(serverUrl); @@ -219,8 +224,12 @@ export const fetchMyChannelsForTeam = async (serverUrl: string, teamId: string, }, []); if (!fetchOnly) { - storeMyChannelsForTeam(serverUrl, teamId, channels, memberships); - storeCategories(serverUrl, categories, true); // Re-sync + const {models: chModels} = await storeMyChannelsForTeam(serverUrl, teamId, channels, memberships, true); + const {models: catModels} = await storeCategories(serverUrl, categories, true, true); // Re-sync + const models = (chModels || []).concat(catModels || []); + if (models.length) { + await operator.batchRecords(models); + } } return {channels, memberships, categories};