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

This commit is contained in:
Denis Bykhov 2025-03-22 18:32:28 +05:00 committed by GitHub
parent 58eb205688
commit 2a735553e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1810,26 +1810,49 @@ export class PostgresAdapter extends PostgresAdapterBase {
this._helper.domains = new Set(resultDomains as Domain[])
}
private process (ops: OperationBulk, tx: Tx): void {
switch (tx._class) {
case core.class.TxCreateDoc:
ops.add.push(TxProcessor.createDoc2Doc(tx as TxCreateDoc<Doc>))
break
case core.class.TxUpdateDoc:
ops.updates.push(tx as TxUpdateDoc<Doc>)
break
case core.class.TxRemoveDoc:
ops.removes.push(tx as TxRemoveDoc<Doc>)
break
case core.class.TxMixin:
ops.mixins.push(tx as TxMixin<Doc, Doc>)
break
case core.class.TxApplyIf:
return undefined
default:
console.error('Unknown/Unsupported operation:', tx._class, tx)
break
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) {
case core.class.TxCreateDoc:
ops.add.push(TxProcessor.createDoc2Doc(tx as TxCreateDoc<Doc>))
break
case core.class.TxUpdateDoc: {
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
}
case core.class.TxRemoveDoc:
ops.removes.push(tx as TxRemoveDoc<Doc>)
break
case core.class.TxMixin:
ops.mixins.push(tx as TxMixin<Doc, Doc>)
break
case core.class.TxApplyIf:
break
default:
console.error('Unknown/Unsupported operation:', tx._class, tx)
break
}
}
ops.updates.push(...updateGroup.values())
return ops
}
private async txMixin (ctx: MeasureContext, tx: TxMixin<Doc, Doc>, schemaFields: SchemaAndFields): Promise<TxResult> {
@ -1878,15 +1901,8 @@ export class PostgresAdapter extends PostgresAdapterBase {
if (domain === undefined) {
continue
}
const ops: OperationBulk = {
add: [],
mixins: [],
removes: [],
updates: []
}
for (const tx of txs) {
this.process(ops, tx)
}
const ops = this.process(txs)
const domainFields = getSchemaAndFields(domain)
if (ops.add.length > 0) {