Skip to content

Fix Mongo table scans when using OAuthAccessToken.find({ clientId });

git push --set-upstream origin 2409-fix-oauth-access-token-mongo-table-scans

Fix https://gitlab.com/gitlab-org/gitter/webapp/issues/2409

We no longer scan the whole database(inefficient) when trying to find all tokens for a given clientId

Testing strategy

running following commands in the mongo shell

$ gitter mongo
troupeSet:PRIMARY> db.adminCommand( { setParameter: 1, notablescan: 1 } )
troupeSet:PRIMARY> db.oauthaccesstokens.find({clientId: 'abc'});
// error
troupeSet:PRIMARY> db.oauthaccesstokens.createIndex({ clientId: 1 })
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 3,
	"numIndexesAfter" : 4,
	"ok" : 1
}
troupeSet:PRIMARY> db.oauthaccesstokens.find({clientId: 'abc'});
// no error

TODO:

  • Add index in production, db.oauthaccesstokens.createIndex({ clientId: 1 })
Edited by Eric Eastwood

Merge request reports