Summary
The CentralAuthUser::getBlocks method performs queries to get the local blocks of users, however, the query is uncached. Ideally these queries should be possible to cache and maybe some work looked into avoiding the hundreds of replica queries needed to check this.
Background
- The CentralAuthUser::getBlocks method is partly uncached
- Specifically, the method does cache the wikis that the user is on but does not cache the checks for local blocks on those wikis
- This can cause at least 2 queries on every wiki that the user has a local account on
- At worst this can be 1600 replica reads from multiple DB sections on WMF wikis
- It may be hard to improve the cache for this beyond what is already there, but perhaps we could consider caching the list that's displayed in the UserInfoCard for a certain amount of time?
- That would avoid slower requests for users with loads of local accounts if their card is opened frequently by other users
- It seems that CentralAuthUser::getBlocks does not use the cache of local user data provided by ::queryAttached, which means that it appears the queries are duplicated
- We could see about using the data from ::queryAttached instead of calling ::getBlocks
Examples
For SBassett (WMF) (who has 189 local accounts) it took 30% of the total time to generate the UserInfoCard data:
Another example user who has 820 local accounts had 36% of the request be taken up by checking local blocks which totalled 2 seconds:
For users who have very few local accounts it takes 4% of the request time:
Technical notes
- TBD, but potentially one of:
- CentralAuthUser::getBlocks is better cached or the code which calls it caches the returned value
- CentralAuthUser::getBlocks tries to use the data from CentralAuthUser::queryAttached if it has already been called instead of loading it again
- CheckUser-UserInfoCard uses the data from CentralAuthUser::queryAttached instead of calling CentralAuthUser::getBlocks
Acceptance criteria
- Calls to CentralAuthUser::getBlocks are better cached to avoid slowing the API down


