mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-03 11:43:26 +00:00
Merge pull request #5756 from overleaf/tm-history-batched-update-descending
Add BATCH_DESCENDING to reverse processing order of batchedUpdate GitOrigin-RevId: fb6aff20713dfd8fe6c6a78b64505d96ce4bfb14
This commit is contained in:
parent
5c5f42df1f
commit
302a6fddc8
1 changed files with 7 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
const { ReadPreference, ObjectId } = require('mongodb')
|
const { ReadPreference, ObjectId } = require('mongodb')
|
||||||
const { db, waitForDb } = require('../../app/src/infrastructure/mongodb')
|
const { db, waitForDb } = require('../../app/src/infrastructure/mongodb')
|
||||||
|
|
||||||
|
const BATCH_DESCENDING = process.env.BATCH_DESCENDING === 'true'
|
||||||
const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 1000
|
const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 1000
|
||||||
let BATCH_LAST_ID
|
let BATCH_LAST_ID
|
||||||
if (process.env.BATCH_LAST_ID) {
|
if (process.env.BATCH_LAST_ID) {
|
||||||
|
@ -10,12 +11,16 @@ if (process.env.BATCH_LAST_ID) {
|
||||||
async function getNextBatch(collection, query, maxId, projection, options) {
|
async function getNextBatch(collection, query, maxId, projection, options) {
|
||||||
maxId = maxId || BATCH_LAST_ID
|
maxId = maxId || BATCH_LAST_ID
|
||||||
if (maxId) {
|
if (maxId) {
|
||||||
query._id = { $gt: maxId }
|
if (BATCH_DESCENDING) {
|
||||||
|
query._id = { $lt: maxId }
|
||||||
|
} else {
|
||||||
|
query._id = { $gt: maxId }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const entries = await collection
|
const entries = await collection
|
||||||
.find(query, options)
|
.find(query, options)
|
||||||
.project(projection)
|
.project(projection)
|
||||||
.sort({ _id: 1 })
|
.sort({ _id: BATCH_DESCENDING ? -1 : 1 })
|
||||||
.limit(BATCH_SIZE)
|
.limit(BATCH_SIZE)
|
||||||
.toArray()
|
.toArray()
|
||||||
return entries
|
return entries
|
||||||
|
|
Loading…
Reference in a new issue