diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 11d480e873..5feac91b64 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -441,6 +441,8 @@ async function buildModel ( ) }) + userTx.sort(compareTxes) + let txes = systemTx.concat(userTx) if (modelFilter !== undefined) { txes = await modelFilter(txes) @@ -473,3 +475,8 @@ function getLastTxTime (txes: Tx[]): number { } return lastTxTime } + +function compareTxes (a: Tx, b: Tx): number { + const result = a._id.localeCompare(b._id) + return result !== 0 ? result : a.modifiedOn - b.modifiedOn +} diff --git a/server/mongo/src/storage.ts b/server/mongo/src/storage.ts index 26470c664c..37f63b6665 100644 --- a/server/mongo/src/storage.ts +++ b/server/mongo/src/storage.ts @@ -1613,7 +1613,7 @@ class MongoTxAdapter extends MongoAdapterBase implements TxAdapter { @withContext('get-model') async getModel (ctx: MeasureContext): Promise { const txCollection = this.db.collection(DOMAIN_TX) - const cursor = txCollection.find({ objectSpace: core.space.Model }) + const cursor = txCollection.find({ objectSpace: core.space.Model }, { sort: { _id: 1, modifiedOn: 1 } }) const model = await toArray(cursor) // We need to put all core.account.System transactions first const systemTx: Tx[] = []