Fix user model updates (#924)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2022-02-03 16:02:54 +07:00 committed by GitHub
parent 5599a8c257
commit e7c0f2406a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -134,7 +134,14 @@ export async function createClient (
}
const conn = await connect(txHander)
const txes = await conn.findAll(core.class.Tx, { objectSpace: core.space.Model }, { sort: { _id: SortingOrder.Ascending } })
const atxes = await conn.findAll(core.class.Tx, { objectSpace: core.space.Model }, { sort: { _id: SortingOrder.Ascending } })
const systemTr: Tx[] = []
const userTx: Tx[] = []
atxes.forEach(tx => ((tx.modifiedBy === core.account.System) ? systemTr : userTx).push(tx))
const txes = systemTr.concat(userTx)
const txMap = new Map<Ref<Tx>, Ref<Tx>>()
for (const tx of txes) txMap.set(tx._id, tx._id)

View File

@ -525,7 +525,14 @@ class MongoTxAdapter extends MongoAdapterBase implements TxAdapter {
}
async getModel (): Promise<Tx[]> {
return await this.db.collection(DOMAIN_TX).find<Tx>({ objectSpace: core.space.Model }).sort({ _id: 1 }).toArray()
const model = await this.db.collection(DOMAIN_TX).find<Tx>({ objectSpace: core.space.Model }).sort({ _id: 1 }).toArray()
// We need to put all core.account.System transactions first
const systemTr: Tx[] = []
const userTx: Tx[] = []
model.forEach(tx => ((tx.modifiedBy === core.account.System) ? systemTr : userTx).push(tx))
return systemTr.concat(userTx)
}
}