Skip to content

Commit be8903a

Browse files
authored
fix: sort model (#7053)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
1 parent cf6ff92 commit be8903a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/core/src/client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ async function buildModel (
441441
)
442442
})
443443

444+
userTx.sort(compareTxes)
445+
444446
let txes = systemTx.concat(userTx)
445447
if (modelFilter !== undefined) {
446448
txes = await modelFilter(txes)
@@ -473,3 +475,8 @@ function getLastTxTime (txes: Tx[]): number {
473475
}
474476
return lastTxTime
475477
}
478+
479+
function compareTxes (a: Tx, b: Tx): number {
480+
const result = a._id.localeCompare(b._id)
481+
return result !== 0 ? result : a.modifiedOn - b.modifiedOn
482+
}

server/mongo/src/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ class MongoTxAdapter extends MongoAdapterBase implements TxAdapter {
16131613
@withContext('get-model')
16141614
async getModel (ctx: MeasureContext): Promise<Tx[]> {
16151615
const txCollection = this.db.collection<Tx>(DOMAIN_TX)
1616-
const cursor = txCollection.find({ objectSpace: core.space.Model })
1616+
const cursor = txCollection.find({ objectSpace: core.space.Model }, { sort: { _id: 1, modifiedOn: 1 } })
16171617
const model = await toArray<Tx>(cursor)
16181618
// We need to put all core.account.System transactions first
16191619
const systemTx: Tx[] = []

0 commit comments

Comments
 (0)