mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-12 10:25:51 +00:00
Fix sql batch update (#8296)
Some checks failed
CI / build (push) Has been cancelled
CI / uitest (push) Has been cancelled
CI / uitest-pg (push) Has been cancelled
CI / uitest-qms (push) Has been cancelled
CI / uitest-workspaces (push) Has been cancelled
CI / svelte-check (push) Has been cancelled
CI / formatting (push) Has been cancelled
CI / test (push) Has been cancelled
CI / docker-build (push) Has been cancelled
CI / dist-build (push) Has been cancelled
Some checks failed
CI / build (push) Has been cancelled
CI / uitest (push) Has been cancelled
CI / uitest-pg (push) Has been cancelled
CI / uitest-qms (push) Has been cancelled
CI / uitest-workspaces (push) Has been cancelled
CI / svelte-check (push) Has been cancelled
CI / formatting (push) Has been cancelled
CI / test (push) Has been cancelled
CI / docker-build (push) Has been cancelled
CI / dist-build (push) Has been cancelled
This commit is contained in:
parent
58eb205688
commit
2a735553e9
@ -1810,14 +1810,34 @@ export class PostgresAdapter extends PostgresAdapterBase {
|
|||||||
this._helper.domains = new Set(resultDomains as Domain[])
|
this._helper.domains = new Set(resultDomains as Domain[])
|
||||||
}
|
}
|
||||||
|
|
||||||
private process (ops: OperationBulk, tx: Tx): void {
|
private process (txes: Tx[]): OperationBulk {
|
||||||
|
const ops: OperationBulk = {
|
||||||
|
add: [],
|
||||||
|
mixins: [],
|
||||||
|
removes: [],
|
||||||
|
updates: []
|
||||||
|
}
|
||||||
|
const updateGroup = new Map<Ref<Doc>, TxUpdateDoc<Doc>>()
|
||||||
|
for (const tx of txes) {
|
||||||
switch (tx._class) {
|
switch (tx._class) {
|
||||||
case core.class.TxCreateDoc:
|
case core.class.TxCreateDoc:
|
||||||
ops.add.push(TxProcessor.createDoc2Doc(tx as TxCreateDoc<Doc>))
|
ops.add.push(TxProcessor.createDoc2Doc(tx as TxCreateDoc<Doc>))
|
||||||
break
|
break
|
||||||
case core.class.TxUpdateDoc:
|
case core.class.TxUpdateDoc: {
|
||||||
ops.updates.push(tx as TxUpdateDoc<Doc>)
|
const updateTx = tx as TxUpdateDoc<Doc>
|
||||||
|
if (isOperator(updateTx.operations)) {
|
||||||
|
ops.updates.push(updateTx)
|
||||||
|
} else {
|
||||||
|
const current = updateGroup.get(updateTx.objectId)
|
||||||
|
if (current !== undefined) {
|
||||||
|
current.operations = { ...current.operations, ...updateTx.operations }
|
||||||
|
updateGroup.set(updateTx.objectId, current)
|
||||||
|
} else {
|
||||||
|
updateGroup.set(updateTx.objectId, updateTx)
|
||||||
|
}
|
||||||
|
}
|
||||||
break
|
break
|
||||||
|
}
|
||||||
case core.class.TxRemoveDoc:
|
case core.class.TxRemoveDoc:
|
||||||
ops.removes.push(tx as TxRemoveDoc<Doc>)
|
ops.removes.push(tx as TxRemoveDoc<Doc>)
|
||||||
break
|
break
|
||||||
@ -1825,12 +1845,15 @@ export class PostgresAdapter extends PostgresAdapterBase {
|
|||||||
ops.mixins.push(tx as TxMixin<Doc, Doc>)
|
ops.mixins.push(tx as TxMixin<Doc, Doc>)
|
||||||
break
|
break
|
||||||
case core.class.TxApplyIf:
|
case core.class.TxApplyIf:
|
||||||
return undefined
|
break
|
||||||
default:
|
default:
|
||||||
console.error('Unknown/Unsupported operation:', tx._class, tx)
|
console.error('Unknown/Unsupported operation:', tx._class, tx)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ops.updates.push(...updateGroup.values())
|
||||||
|
return ops
|
||||||
|
}
|
||||||
|
|
||||||
private async txMixin (ctx: MeasureContext, tx: TxMixin<Doc, Doc>, schemaFields: SchemaAndFields): Promise<TxResult> {
|
private async txMixin (ctx: MeasureContext, tx: TxMixin<Doc, Doc>, schemaFields: SchemaAndFields): Promise<TxResult> {
|
||||||
await ctx.with('tx-mixin', { _class: tx.objectClass, mixin: tx.mixin }, async (ctx) => {
|
await ctx.with('tx-mixin', { _class: tx.objectClass, mixin: tx.mixin }, async (ctx) => {
|
||||||
@ -1878,15 +1901,8 @@ export class PostgresAdapter extends PostgresAdapterBase {
|
|||||||
if (domain === undefined) {
|
if (domain === undefined) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const ops: OperationBulk = {
|
|
||||||
add: [],
|
const ops = this.process(txs)
|
||||||
mixins: [],
|
|
||||||
removes: [],
|
|
||||||
updates: []
|
|
||||||
}
|
|
||||||
for (const tx of txs) {
|
|
||||||
this.process(ops, tx)
|
|
||||||
}
|
|
||||||
|
|
||||||
const domainFields = getSchemaAndFields(domain)
|
const domainFields = getSchemaAndFields(domain)
|
||||||
if (ops.add.length > 0) {
|
if (ops.add.length > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user