mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-05 10:29:51 +03:00
UBERF-8596: Fix CollectionCUD migration performance (#7190)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
d4394e8a2a
commit
6292e58119
@ -290,38 +290,53 @@ export const coreOperation: MigrateOperation = {
|
|||||||
await client.update(DOMAIN_SPACE, { '%hash%': { $exists: true } }, { $set: { '%hash%': null } })
|
await client.update(DOMAIN_SPACE, { '%hash%': { $exists: true } }, { $set: { '%hash%': null } })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
state: 'remove-github-patches',
|
||||||
|
func: async (client) => {
|
||||||
|
await client.update(
|
||||||
|
DOMAIN_TX,
|
||||||
|
{
|
||||||
|
objectClass: 'tracker:class:Issue',
|
||||||
|
collection: 'pullRequests',
|
||||||
|
'tx.attributes.patch': { $exists: true }
|
||||||
|
},
|
||||||
|
{ $unset: { 'tx.attributes.patch': 1 } }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
state: 'remove-collection-txes',
|
state: 'remove-collection-txes',
|
||||||
func: async (client) => {
|
func: async (client) => {
|
||||||
let processed = 0
|
let processed = 0
|
||||||
while (true) {
|
const iterator = await client.traverse<TxCUD<Doc>>(DOMAIN_TX, {
|
||||||
const txes = await client.find<TxCUD<Doc>>(
|
|
||||||
DOMAIN_TX,
|
|
||||||
{
|
|
||||||
_class: 'core:class:TxCollectionCUD' as Ref<Class<Doc>>
|
_class: 'core:class:TxCollectionCUD' as Ref<Class<Doc>>
|
||||||
},
|
})
|
||||||
{ limit: 5000 }
|
while (true) {
|
||||||
)
|
const txes = await iterator.next(1000)
|
||||||
if (txes.length === 0) break
|
if (txes === null || txes.length === 0) break
|
||||||
for (const tx of txes) {
|
processed += txes.length
|
||||||
processed++
|
try {
|
||||||
const { _id, ...ops } = (tx as any).tx
|
await client.deleteMany(DOMAIN_TX, {
|
||||||
await client.update(
|
_id: { $in: txes.map((it) => it._id) }
|
||||||
|
})
|
||||||
|
await client.create(
|
||||||
DOMAIN_TX,
|
DOMAIN_TX,
|
||||||
{ _id: tx._id },
|
txes.map((tx) => {
|
||||||
{
|
const { collection, objectId, objectClass } = tx
|
||||||
$set: {
|
return {
|
||||||
attachedTo: tx.objectId,
|
collection,
|
||||||
attachedToClass: tx.objectClass,
|
attachedTo: objectId,
|
||||||
...ops
|
attachedToClass: objectClass,
|
||||||
}
|
...(tx as any).tx
|
||||||
}
|
}
|
||||||
|
})
|
||||||
)
|
)
|
||||||
if (processed % 1000 === 0) {
|
} catch (err: any) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
console.log('processed', processed)
|
console.log('processed', processed)
|
||||||
}
|
}
|
||||||
}
|
await iterator.close()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user