bulk everything

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-10-08 11:18:06 +02:00
parent d89b8827ea
commit 157e7874c4
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
2 changed files with 25 additions and 16 deletions

View File

@ -16,7 +16,7 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte'
import type { Ref, Class, Doc, Space, SpaceWithStates, FindOptions, State, TxBulkWrite } from '@anticrm/core'
import type { Ref, Class, Doc, Space, SpaceWithStates, FindOptions, State, TxBulkWrite, TxCUD } from '@anticrm/core'
import { getResource } from '@anticrm/platform'
import { buildModel } from '../utils'
import { getClient } from '@anticrm/presentation'
@ -78,30 +78,24 @@
async function move(to: number, state: Ref<State>) {
console.log('move version 12')
const id = dragCard._id
if (dragCardInitialState !== state)
client.updateDoc(_class, space, id, { state })
const txes: TxCUD<Doc>[] = []
if (dragCardInitialPosition !== to) {
const remove = client.txFactory.createTxUpdateDoc(core.class.SpaceWithStates, core.space.Model, space, {
txes.push(client.txFactory.createTxUpdateDoc(core.class.SpaceWithStates, core.space.Model, space, {
$pull: {
order: id
}
})
}))
const add = client.txFactory.createTxUpdateDoc(core.class.SpaceWithStates, core.space.Model, space, {
txes.push(client.txFactory.createTxUpdateDoc(core.class.SpaceWithStates, core.space.Model, space, {
$push: {
order: {
$each: [id],
$position: to
}
}
})
const updateTx = client.txFactory.createTxBulkWrite(core.space.Model, [remove, add])
await client.tx(updateTx)
}))
// await client.updateDoc(core.class.SpaceWithStates, core.space.Model, space, {
// $pull: {
@ -118,6 +112,14 @@
// }
// })
}
if (dragCardInitialState !== state)
txes.push(client.txFactory.createTxUpdateDoc(_class, space, id, { state }))
if (txes.length > 0) {
const updateTx = client.txFactory.createTxBulkWrite(space, txes)
await client.tx(updateTx)
}
}
function getValue(doc: Doc, key: string): any {

View File

@ -14,7 +14,7 @@
// limitations under the License.
//
import type { ServerStorage, Domain, Tx, TxCUD, Doc, Ref, Class, DocumentQuery, FindResult, FindOptions, Storage } from '@anticrm/core'
import type { ServerStorage, Domain, Tx, TxCUD, Doc, Ref, Class, DocumentQuery, FindResult, FindOptions, Storage, TxBulkWrite } from '@anticrm/core'
import core, { Hierarchy, DOMAIN_TX } from '@anticrm/core'
import type { FullTextAdapterFactory, FullTextAdapter } from './types'
import { FullTextIndex } from './fulltext'
@ -87,13 +87,20 @@ class TServerStorage implements ServerStorage {
return adapter
}
private routeTx (tx: Tx): Promise<void> {
private async routeTx (tx: Tx): Promise<void> {
if (this.hierarchy.isDerived(tx._class, core.class.TxCUD)) {
const txCUD = tx as TxCUD<Doc>
const domain = this.hierarchy.getDomain(txCUD.objectClass)
return this.getAdapter(domain).tx(txCUD)
return await this.getAdapter(domain).tx(txCUD)
} else {
throw new Error('not implemented (not derived from TxCUD)')
if (this.hierarchy.isDerived(tx._class, core.class.TxBulkWrite)) {
const bulkWrite = tx as TxBulkWrite
for (const tx of bulkWrite.txes) {
await this.tx(tx)
}
} else {
throw new Error('not implemented (routeTx)')
}
}
}