[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:
Jakob Ackermann
2025-06-05 11:10:19 +02:00
committed by Copybot
parent d7833afd35
commit 3b684e08ca
2 changed files with 12 additions and 0 deletions

View File

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

View File

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