From 269701f97dd3108521239952b28b1bd5067abcd6 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 25 Jul 2022 17:36:57 +0100 Subject: [PATCH] moar bulkdocs --- packages/worker/src/api/controllers/global/users.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/worker/src/api/controllers/global/users.ts b/packages/worker/src/api/controllers/global/users.ts index c26dfe479a..80a8ff4c9c 100644 --- a/packages/worker/src/api/controllers/global/users.ts +++ b/packages/worker/src/api/controllers/global/users.ts @@ -140,14 +140,17 @@ export const destroy = async (ctx: any) => { // Remove asssosicated groups if (groups) { + let groupsPromises = [] for (const groupId of groups) { let group = await db.get(groupId) let updatedUsersGroup = group.users.filter( (groupUser: any) => groupUser.email !== user.email ) group.users = updatedUsersGroup - await db.put(group) + groupsPromises.push(db.put(group)) } + + await db.bulkDocs(groupsPromises) } ctx.body = { @@ -169,13 +172,17 @@ export const bulkDelete = async (ctx: any) => { keys: Object.keys(groupsToModify), }) ).rows.map((group: any) => group.doc) + + let groupsPromises = [] for (const group of groups) { let updatedUsersGroup = group.users.filter( (groupUser: any) => !groupsToModify[group._id].includes(groupUser._id) ) group.users = updatedUsersGroup - await db.put(group) + groupsPromises.push(db.put(group)) } + + await db.bulkDocs(groupsPromises) } ctx.body = {