mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 18:20:09 +02:00
[web] fetch token users in a single db query per access mode (#26078)
* [web] skip db query when getting empty list of users * [web] fetch token users in a single db query per access mode GitOrigin-RevId: fa5d9edcb761bd5d5e5ea07d137a5a86efdbdd5c
This commit is contained in:
@@ -269,6 +269,7 @@ const UserGetter = {
|
||||
getUsers(query, projection, callback) {
|
||||
try {
|
||||
query = normalizeMultiQuery(query)
|
||||
if (query?._id?.$in?.length === 0) return callback(null, []) // shortcut for getUsers([])
|
||||
db.users.find(query, { projection }).toArray(callback)
|
||||
} catch (err) {
|
||||
callback(err)
|
||||
|
||||
@@ -119,6 +119,17 @@ describe('UserGetter', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call mongo with empty list', function (done) {
|
||||
const query = []
|
||||
const projection = { email: 1 }
|
||||
this.UserGetter.getUsers(query, projection, (error, users) => {
|
||||
expect(error).to.not.exist
|
||||
expect(users).to.deep.equal([])
|
||||
expect(this.find).to.not.have.been.called
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not allow null query', function (done) {
|
||||
this.UserGetter.getUser(null, {}, error => {
|
||||
error.should.exist
|
||||
|
||||
Reference in New Issue
Block a user