diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 490b41eabb..58ffdde563 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -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>() for (const tx of txes) txMap.set(tx._id, tx._id) diff --git a/server/mongo/src/storage.ts b/server/mongo/src/storage.ts index eaff28a6fb..2e27336d68 100644 --- a/server/mongo/src/storage.ts +++ b/server/mongo/src/storage.ts @@ -525,7 +525,14 @@ class MongoTxAdapter extends MongoAdapterBase implements TxAdapter { } async getModel (): Promise { - return await this.db.collection(DOMAIN_TX).find({ objectSpace: core.space.Model }).sort({ _id: 1 }).toArray() + const model = await this.db.collection(DOMAIN_TX).find({ 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) } }