Skip to content

Commit fa7bd90

Browse files
fix: error in list teams
1 parent 9387a58 commit fa7bd90

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

apps/meteor/server/methods/browseChannels.js

+23-13
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,22 @@ async function getChannelsAndGroups(user, canViewAnon, searchTerm, sort, paginat
104104
};
105105
}
106106

107-
const getChannelsCountForTeam = mem((teamId) => Promise.await(Rooms.findByTeamId(teamId, { projection: { _id: 1 } }).count()), {
108-
maxAge: 2000,
109-
});
107+
const getChannelsCountForTeam = mem(
108+
(teamId) => {
109+
return Rooms.findByTeamId(teamId, { projection: { _id: 1 } });
110+
},
111+
{
112+
maxAge: 2000,
113+
},
114+
);
110115

111116
async function getTeams(user, searchTerm, sort, pagination) {
112117
if (!user) {
113118
return;
114119
}
115120

116121
const userSubs = Subscriptions.cachedFindByUserId(user._id).fetch();
122+
117123
const ids = userSubs.map((sub) => sub.rid);
118124
const { cursor, totalCount } = Rooms.findPaginatedContainingNameOrFNameInIdsAsTeamMain(
119125
searchTerm ? new RegExp(searchTerm, 'i') : null,
@@ -143,19 +149,23 @@ async function getTeams(user, searchTerm, sort, pagination) {
143149
},
144150
);
145151

146-
const [rooms, total] = await Promise.all([
147-
cursor
148-
.map((room) => ({
149-
...room,
150-
roomsCount: getChannelsCountForTeam(room.teamId),
151-
}))
152-
.toArray(),
153-
totalCount,
154-
]);
152+
const roomsPromises = cursor.map((room) => room).toArray();
153+
154+
const [rooms] = await Promise.all([roomsPromises]);
155+
156+
const teams = [];
157+
158+
for await (const room of rooms) {
159+
const result = await getChannelsCountForTeam(room.teamId).toArray();
160+
161+
teams.push({ ...room, roomsCount: result.length });
162+
}
163+
164+
const [total] = await Promise.all([totalCount]);
155165

156166
return {
157167
total,
158-
results: rooms,
168+
results: teams,
159169
};
160170
}
161171

0 commit comments

Comments
 (0)