fix: sort model (#7053)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2024-10-28 16:09:41 +07:00 committed by GitHub
parent cf6ff9293d
commit be8903ab96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -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
}

View File

@ -1613,7 +1613,7 @@ class MongoTxAdapter extends MongoAdapterBase implements TxAdapter {
@withContext('get-model')
async getModel (ctx: MeasureContext): Promise<Tx[]> {
const txCollection = this.db.collection<Tx>(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<Tx>(cursor)
// We need to put all core.account.System transactions first
const systemTx: Tx[] = []