mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
Merge pull request #21506 from overleaf/jpa-fix-batched-update-edge
[web] fix edge behavior of batchedUpdate GitOrigin-RevId: 5d1c0b884aa02c52682d114fa66b2d9b201e724e
This commit is contained in:
parent
2402f9ea99
commit
bf2ad1952c
2 changed files with 71 additions and 2 deletions
|
@ -91,12 +91,12 @@ async function getNextBatch(
|
||||||
if (BATCH_DESCENDING) {
|
if (BATCH_DESCENDING) {
|
||||||
query._id = {
|
query._id = {
|
||||||
$gt: end,
|
$gt: end,
|
||||||
$lt: start,
|
$lte: start,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
query._id = {
|
query._id = {
|
||||||
$gt: start,
|
$gt: start,
|
||||||
$lt: end,
|
$lte: end,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await collection
|
return await collection
|
||||||
|
|
|
@ -36,4 +36,73 @@ describe('BatchedUpdateTests', function () {
|
||||||
{ content: '42' },
|
{ content: '42' },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('can handle ids sitting on the edge', async function () {
|
||||||
|
const edge = '3028de800000000000000000'
|
||||||
|
await db.systemmessages.insertOne({
|
||||||
|
content: '1',
|
||||||
|
_id: new ObjectId('300000000000000000000000'),
|
||||||
|
})
|
||||||
|
await db.systemmessages.insertOne({
|
||||||
|
content: '2',
|
||||||
|
_id: new ObjectId(),
|
||||||
|
})
|
||||||
|
await db.systemmessages.insertOne({
|
||||||
|
content: '3',
|
||||||
|
_id: new ObjectId('400000000000000000000000'),
|
||||||
|
})
|
||||||
|
const { stderr } = spawnSync(
|
||||||
|
process.argv0,
|
||||||
|
[
|
||||||
|
'--input-type=module',
|
||||||
|
'-e',
|
||||||
|
'import BatchedUpdateModule from "./scripts/helpers/batchedUpdate.mjs"; BatchedUpdateModule.batchedUpdateWithResultHandling("systemmessages", { content: { $ne: "42" }}, { $set: { content: "42" } })',
|
||||||
|
],
|
||||||
|
{ encoding: 'utf-8' }
|
||||||
|
)
|
||||||
|
expect(
|
||||||
|
await db.systemmessages.find({}).project({ content: 1, _id: 0 }).toArray()
|
||||||
|
).to.deep.equal([{ content: '42' }, { content: '42' }, { content: '42' }])
|
||||||
|
expect(stderr).to.include('Completed batch ending 300000000000000000000000')
|
||||||
|
expect(stderr).to.include(`Completed batch ending ${edge}`) // hit the edge
|
||||||
|
expect(stderr).to.include('Completed batch ending 400000000000000000000000')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can handle ids sitting on the edge descending', async function () {
|
||||||
|
const edge = '3fd721800000000000000000'
|
||||||
|
await db.systemmessages.insertOne({
|
||||||
|
content: '1',
|
||||||
|
_id: new ObjectId('300000000000000000000000'),
|
||||||
|
})
|
||||||
|
await db.systemmessages.insertOne({
|
||||||
|
content: '2',
|
||||||
|
_id: new ObjectId(edge),
|
||||||
|
})
|
||||||
|
await db.systemmessages.insertOne({
|
||||||
|
content: '3',
|
||||||
|
_id: new ObjectId('400000000000000000000000'),
|
||||||
|
})
|
||||||
|
const { stderr } = spawnSync(
|
||||||
|
process.argv0,
|
||||||
|
[
|
||||||
|
'--input-type=module',
|
||||||
|
'-e',
|
||||||
|
'import BatchedUpdateModule from "./scripts/helpers/batchedUpdate.mjs"; BatchedUpdateModule.batchedUpdateWithResultHandling("systemmessages", { content: { $ne: "42" }}, { $set: { content: "42" } })',
|
||||||
|
],
|
||||||
|
{
|
||||||
|
encoding: 'utf-8',
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
BATCH_DESCENDING: 'true',
|
||||||
|
BATCH_RANGE_START: '400000000000000000000001',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expect(
|
||||||
|
await db.systemmessages.find({}).project({ content: 1, _id: 0 }).toArray()
|
||||||
|
).to.deep.equal([{ content: '42' }, { content: '42' }, { content: '42' }])
|
||||||
|
expect(stderr).to.include('Completed batch ending 400000000000000000000000')
|
||||||
|
expect(stderr).to.include(`Completed batch ending ${edge}`) // hit the edge
|
||||||
|
expect(stderr).to.include('Completed batch ending 300000000000000000000000')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue