Skip to content

Commit

Permalink
UBERF-8596: Fix CollectionCUD migration performance
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <[email protected]>
  • Loading branch information
haiodo committed Nov 18, 2024
1 parent 641e72f commit f32a965
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions models/core/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,38 +290,53 @@ export const coreOperation: MigrateOperation = {
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',
func: async (client) => {
let processed = 0
const iterator = await client.traverse<TxCUD<Doc>>(DOMAIN_TX, {
_class: 'core:class:TxCollectionCUD' as Ref<Class<Doc>>
})
while (true) {
const txes = await client.find<TxCUD<Doc>>(
DOMAIN_TX,
{
_class: 'core:class:TxCollectionCUD' as Ref<Class<Doc>>
},
{ limit: 5000 }
)
if (txes.length === 0) break
for (const tx of txes) {
processed++
const { _id, ...ops } = (tx as any).tx
await client.update(
const txes = await iterator.next(1000)
if (txes === null || txes.length === 0) break
processed += txes.length
try {
await client.deleteMany(DOMAIN_TX, {
_id: { $in: txes.map((it) => it._id) }
})
await client.create(
DOMAIN_TX,
{ _id: tx._id },
{
$set: {
attachedTo: tx.objectId,
attachedToClass: tx.objectClass,
...ops
txes.map((tx) => {
const { collection, objectId, objectClass } = tx
return {
collection,
attachedTo: objectId,
attachedToClass: objectClass,
...(tx as any).tx
}
}
})
)
if (processed % 1000 === 0) {
console.log('processed', processed)
}
} catch (err: any) {
console.error(err)
}
console.log('processed', processed)
}
await iterator.close()
}
},
{
Expand Down

0 comments on commit f32a965

Please sign in to comment.