@@ -1767,26 +1767,49 @@ class PostgresAdapter extends PostgresAdapterBase {
1767
1767
this . _helper . domains = new Set ( resultDomains as Domain [ ] )
1768
1768
}
1769
1769
1770
- private process ( ops : OperationBulk , tx : Tx ) : void {
1771
- switch ( tx . _class ) {
1772
- case core . class . TxCreateDoc :
1773
- ops . add . push ( TxProcessor . createDoc2Doc ( tx as TxCreateDoc < Doc > ) )
1774
- break
1775
- case core . class . TxUpdateDoc :
1776
- ops . updates . push ( tx as TxUpdateDoc < Doc > )
1777
- break
1778
- case core . class . TxRemoveDoc :
1779
- ops . removes . push ( tx as TxRemoveDoc < Doc > )
1780
- break
1781
- case core . class . TxMixin :
1782
- ops . mixins . push ( tx as TxMixin < Doc , Doc > )
1783
- break
1784
- case core . class . TxApplyIf :
1785
- return undefined
1786
- default :
1787
- console . error ( 'Unknown/Unsupported operation:' , tx . _class , tx )
1788
- break
1770
+ private process ( txes : Tx [ ] ) : OperationBulk {
1771
+ const ops : OperationBulk = {
1772
+ add : [ ] ,
1773
+ mixins : [ ] ,
1774
+ removes : [ ] ,
1775
+ updates : [ ]
1776
+ }
1777
+ const updateGroup = new Map < Ref < Doc > , TxUpdateDoc < Doc > > ( )
1778
+ for ( const tx of txes ) {
1779
+ switch ( tx . _class ) {
1780
+ case core . class . TxCreateDoc :
1781
+ ops . add . push ( TxProcessor . createDoc2Doc ( tx as TxCreateDoc < Doc > ) )
1782
+ break
1783
+ case core . class . TxUpdateDoc : {
1784
+ const updateTx = tx as TxUpdateDoc < Doc >
1785
+ if ( isOperator ( updateTx . operations ) ) {
1786
+ ops . updates . push ( updateTx )
1787
+ } else {
1788
+ const current = updateGroup . get ( updateTx . objectId )
1789
+ if ( current !== undefined ) {
1790
+ current . operations = { ...current . operations , ...updateTx . operations }
1791
+ updateGroup . set ( updateTx . objectId , current )
1792
+ } else {
1793
+ updateGroup . set ( updateTx . objectId , updateTx )
1794
+ }
1795
+ }
1796
+ break
1797
+ }
1798
+ case core . class . TxRemoveDoc :
1799
+ ops . removes . push ( tx as TxRemoveDoc < Doc > )
1800
+ break
1801
+ case core . class . TxMixin :
1802
+ ops . mixins . push ( tx as TxMixin < Doc , Doc > )
1803
+ break
1804
+ case core . class . TxApplyIf :
1805
+ break
1806
+ default :
1807
+ console . error ( 'Unknown/Unsupported operation:' , tx . _class , tx )
1808
+ break
1809
+ }
1789
1810
}
1811
+ ops . updates . push ( ...updateGroup . values ( ) )
1812
+ return ops
1790
1813
}
1791
1814
1792
1815
private async txMixin ( ctx : MeasureContext , tx : TxMixin < Doc , Doc > , schemaFields : SchemaAndFields ) : Promise < TxResult > {
@@ -1835,15 +1858,8 @@ class PostgresAdapter extends PostgresAdapterBase {
1835
1858
if ( domain === undefined ) {
1836
1859
continue
1837
1860
}
1838
- const ops : OperationBulk = {
1839
- add : [ ] ,
1840
- mixins : [ ] ,
1841
- removes : [ ] ,
1842
- updates : [ ]
1843
- }
1844
- for ( const tx of txs ) {
1845
- this . process ( ops , tx )
1846
- }
1861
+
1862
+ const ops = this . process ( txs )
1847
1863
1848
1864
const domainFields = getSchemaAndFields ( domain )
1849
1865
if ( ops . add . length > 0 ) {
0 commit comments