mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #3275 from overleaf/as-fix-confirmed-emails-query
Fix slow query for user with confirmed emails GitOrigin-RevId: aec3429073bf45e192ca8b0b4a2ac90ebf22b510
This commit is contained in:
parent
941241af54
commit
69521047e2
2 changed files with 31 additions and 2 deletions
|
@ -97,13 +97,18 @@ const UserGetter = {
|
|||
callback = projection
|
||||
projection = {}
|
||||
}
|
||||
// $exists: true MUST be set to use the partial index
|
||||
|
||||
const query = {
|
||||
'emails.email': { $in: emails }, // use the index on emails.email
|
||||
emails: {
|
||||
$exists: true,
|
||||
$elemMatch: { email: { $in: emails }, confirmedAt: { $exists: true } }
|
||||
$elemMatch: {
|
||||
email: { $in: emails },
|
||||
confirmedAt: { $exists: true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.users.find(query, { projection }).toArray(callback)
|
||||
},
|
||||
|
||||
|
|
|
@ -380,6 +380,30 @@ describe('UserGetter', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('getUsersByAnyConfirmedEmail', function() {
|
||||
it('should find users by confirmed email', function(done) {
|
||||
const emails = ['confirmed@example.com']
|
||||
|
||||
this.UserGetter.getUsersByAnyConfirmedEmail(emails, (error, users) => {
|
||||
expect(error).to.not.exist
|
||||
expect(this.find).to.be.calledOnceWith(
|
||||
{
|
||||
'emails.email': { $in: emails }, // use the index on emails.email
|
||||
emails: {
|
||||
$exists: true,
|
||||
$elemMatch: {
|
||||
email: { $in: emails },
|
||||
confirmedAt: { $exists: true }
|
||||
}
|
||||
}
|
||||
},
|
||||
{ projection: {} }
|
||||
)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUsersByV1Id', function() {
|
||||
it('should find users by list of v1 ids', function(done) {
|
||||
const v1Ids = [501]
|
||||
|
|
Loading…
Reference in a new issue