mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
transaction ordering
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
6b2f153358
commit
81871cbeeb
@ -17,6 +17,7 @@ import type { Doc, Ref, Class } from './classes'
|
||||
import type { Tx } from './tx'
|
||||
import type { Storage, DocumentQuery, FindOptions, FindResult } from './storage'
|
||||
|
||||
import { SortingOrder } from './storage'
|
||||
import { Hierarchy } from './hierarchy'
|
||||
import { ModelDb } from './memdb'
|
||||
import { DOMAIN_MODEL } from './classes'
|
||||
@ -96,7 +97,7 @@ export async function createClient (
|
||||
}
|
||||
|
||||
const conn = await connect(txHander)
|
||||
const txes = await conn.findAll(core.class.Tx, { objectSpace: core.space.Model })
|
||||
const txes = await conn.findAll(core.class.Tx, { objectSpace: core.space.Model }, { sort: { _id: SortingOrder.Ascending } })
|
||||
|
||||
const txMap = new Map<Ref<Tx>, Ref<Tx>>()
|
||||
for (const tx of txes) txMap.set(tx._id, tx._id)
|
||||
|
@ -57,7 +57,7 @@ export type FindOptions<T extends Doc> = {
|
||||
* @public
|
||||
*/
|
||||
export type SortingQuery<T extends Doc> = {
|
||||
[P in keyof T]?: T[P] extends object ? never : SortingOrder
|
||||
[P in keyof T]?: SortingOrder
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,11 +13,10 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import type { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxCreateDoc, ServerStorage } from '@anticrm/core'
|
||||
import core, { DOMAIN_MODEL, TxProcessor, ModelDb, Hierarchy, DOMAIN_TX, TxFactory } from '@anticrm/core'
|
||||
import core, { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxCreateDoc, ServerStorage, SortingOrder, DOMAIN_MODEL, TxProcessor, ModelDb, Hierarchy, DOMAIN_TX, TxFactory } from '@anticrm/core'
|
||||
|
||||
import { Triggers } from '@anticrm/server-core'
|
||||
import { MongoClient, Db, Filter, Document } from 'mongodb'
|
||||
import { MongoClient, Db, Filter, Document, Sort } from 'mongodb'
|
||||
|
||||
function translateQuery<T extends Doc> (query: DocumentQuery<T>): Filter<T> {
|
||||
return query as Filter<T>
|
||||
@ -69,7 +68,18 @@ class MongoStorage implements ServerStorage {
|
||||
const domain = this.hierarchy.getDomain(_class)
|
||||
console.log('findAll', _class, domain, query)
|
||||
if (domain === DOMAIN_MODEL) return await this.modeldb.findAll(_class, query, options)
|
||||
return await this.db.collection(domain).find<T>(translateQuery(query)).toArray()
|
||||
let cursor = this.db.collection(domain).find<T>(translateQuery(query))
|
||||
if (options !== null && options !== undefined) {
|
||||
if (options.sort !== undefined) {
|
||||
const sort: Sort = {}
|
||||
for (const key in options.sort) {
|
||||
const order = options.sort[key] === SortingOrder.Ascending ? 1 : -1
|
||||
sort[key] = order
|
||||
}
|
||||
cursor = cursor.sort(sort)
|
||||
}
|
||||
}
|
||||
return await cursor.toArray()
|
||||
}
|
||||
|
||||
async tx (tx: Tx): Promise<Tx[]> {
|
||||
@ -97,7 +107,7 @@ export async function createStorage (url: string, dbName: string): Promise<Serve
|
||||
const hierarchy = new Hierarchy()
|
||||
const triggers = new Triggers(new TxFactory(core.account.System))
|
||||
|
||||
const txes = await db.collection(DOMAIN_TX).find<Tx>({ objectSpace: core.space.Model }).toArray()
|
||||
const txes = await db.collection(DOMAIN_TX).find<Tx>({ objectSpace: core.space.Model }).sort({ _id: 1 }).toArray()
|
||||
for (const tx of txes) {
|
||||
hierarchy.tx(tx)
|
||||
await triggers.tx(tx)
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@anticrm/server",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"main": "lib/index.js",
|
||||
"author": "Anticrm Platform Contributors",
|
||||
"license": "EPL-2.0",
|
||||
|
Loading…
Reference in New Issue
Block a user