Query for querying LDAP identities is running on GitLab.com and taking a lot of time
Earlier today I noticed the following query is now executing on at least project dashboards:
SELECT 1 AS one FROM "identities" WHERE "identities"."user_id" = 209240 AND (provider LIKE 'ldap%' AND extern_uid IS NOT NULL) LIMIT 1
This query occasionally takes up to 40 milliseconds to run. I don't recall seeing this query before, suggesting it may have been recently introduced. This query is problematic not only because of the performance, but also because it will never return data as LDAP is not enabled for GitLab.com. Further this query really should be cached. Thus we should:
- Not run this query if LDAP is not enabled (if we can somehow detect this)
- Cache the results