perf: Fix N+1 queries and optimize database operations (#25630)
* perf: batch database operations and fix N+1 queries * delete * Fix condition for checking CalVideo location activity
This commit is contained in:
1 parent
978c5bdb95
commit
161ebdbbec
4 files changed
+120
-75
No files matched your search
+9
-3
@@ -71,13 +71,19 @@ async function getTeamMembers({
|
||||
});
|
||||
|
||||
const userRepo = new UserRepository(prisma);
|
||||
const users = memberships.map((membership) => membership.user);
|
||||
const enrichedUsers = await userRepo.enrichUsersWithTheirProfileExcludingOrgMetadata(users);
|
||||
const enrichedUserMap = new Map<number, (typeof enrichedUsers)[0]>();
|
||||
enrichedUsers.forEach((enrichedUser) => {
|
||||
enrichedUserMap.set(enrichedUser.id, enrichedUser);
|
||||
});
|
||||
const membershipWithUserProfile = [];
|
||||
for (const membership of memberships) {
|
||||
const enrichedUser = enrichedUserMap.get(membership.user.id);
|
||||
if (!enrichedUser) continue;
|
||||
membershipWithUserProfile.push({
|
||||
...membership,
|
||||
user: await userRepo.enrichUserWithItsProfileExcludingOrgMetadata({
|
||||
user: membership.user,
|
||||
}),
|
||||
user: enrichedUser,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user