mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-22 08:20:39 +00:00
bulk everything
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
d89b8827ea
commit
157e7874c4
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher } from 'svelte'
|
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 { getResource } from '@anticrm/platform'
|
||||||
import { buildModel } from '../utils'
|
import { buildModel } from '../utils'
|
||||||
import { getClient } from '@anticrm/presentation'
|
import { getClient } from '@anticrm/presentation'
|
||||||
@ -78,30 +78,24 @@
|
|||||||
async function move(to: number, state: Ref<State>) {
|
async function move(to: number, state: Ref<State>) {
|
||||||
console.log('move version 12')
|
console.log('move version 12')
|
||||||
const id = dragCard._id
|
const id = dragCard._id
|
||||||
|
const txes: TxCUD<Doc>[] = []
|
||||||
if (dragCardInitialState !== state)
|
|
||||||
client.updateDoc(_class, space, id, { state })
|
|
||||||
|
|
||||||
if (dragCardInitialPosition !== to) {
|
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: {
|
$pull: {
|
||||||
order: id
|
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: {
|
$push: {
|
||||||
order: {
|
order: {
|
||||||
$each: [id],
|
$each: [id],
|
||||||
$position: to
|
$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, {
|
// await client.updateDoc(core.class.SpaceWithStates, core.space.Model, space, {
|
||||||
// $pull: {
|
// $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 {
|
function getValue(doc: Doc, key: string): any {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// limitations under the License.
|
// 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 core, { Hierarchy, DOMAIN_TX } from '@anticrm/core'
|
||||||
import type { FullTextAdapterFactory, FullTextAdapter } from './types'
|
import type { FullTextAdapterFactory, FullTextAdapter } from './types'
|
||||||
import { FullTextIndex } from './fulltext'
|
import { FullTextIndex } from './fulltext'
|
||||||
@ -87,13 +87,20 @@ class TServerStorage implements ServerStorage {
|
|||||||
return adapter
|
return adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
private routeTx (tx: Tx): Promise<void> {
|
private async routeTx (tx: Tx): Promise<void> {
|
||||||
if (this.hierarchy.isDerived(tx._class, core.class.TxCUD)) {
|
if (this.hierarchy.isDerived(tx._class, core.class.TxCUD)) {
|
||||||
const txCUD = tx as TxCUD<Doc>
|
const txCUD = tx as TxCUD<Doc>
|
||||||
const domain = this.hierarchy.getDomain(txCUD.objectClass)
|
const domain = this.hierarchy.getDomain(txCUD.objectClass)
|
||||||
return this.getAdapter(domain).tx(txCUD)
|
return await this.getAdapter(domain).tx(txCUD)
|
||||||
} else {
|
} 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)')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user