Skip to content

Commit

Permalink
ezqms-1069: use bulk operation
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
  • Loading branch information
lexiv0re committed Jul 25, 2024
1 parent d8675c4 commit 8c227ae
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions models/request/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import core, { DOMAIN_TX, type Ref, type TxCreateDoc } from '@hcengineering/core'
import request, { requestId, type Request } from '@hcengineering/request'
import {
type MigrateUpdate,
type MigrationDocumentQuery,
tryMigrate,
type MigrateOperation,
type MigrationClient,
Expand Down Expand Up @@ -44,7 +46,7 @@ async function migrateRequestPersonAccounts (client: MigrationClient): Promise<v
},
{}
)

const operations: { filter: MigrationDocumentQuery<Request>, update: MigrateUpdate<Request> }[] = []
for (const request of requests) {
const newRequestedPersons = request.requested
.map((paId) => personAccountToPersonMap[paId as unknown as Ref<PersonAccount>])
Expand All @@ -56,34 +58,32 @@ async function migrateRequestPersonAccounts (client: MigrationClient): Promise<v
request.rejected != null ? personAccountToPersonMap[request.rejected as unknown as Ref<PersonAccount>] : undefined

if (newRequestedPersons.length > 0) {
await client.update(
DOMAIN_REQUEST,
{
operations.push({
filter: {
_id: request._id
},
{
$set: {
requested: newRequestedPersons,
approved: newApprovedPersons
}
update: {
requested: newRequestedPersons,
approved: newApprovedPersons
}
)
})
}

if (newRejectedPerson !== undefined) {
await client.update(
DOMAIN_REQUEST,
{
operations.push({
filter: {
_id: request._id
},
{
$set: {
rejected: newRejectedPerson
}
update: {
rejected: newRejectedPerson
}
)
})
}
}

if (operations.length > 0) {
await client.bulk(DOMAIN_REQUEST, operations)
}
}

export const requestOperation: MigrateOperation = {
Expand Down

0 comments on commit 8c227ae

Please sign in to comment.