Page MenuHomePhabricator

UserInfoCard: Queries performed by `CentralAuthUser::getBlocks` is uncached and performs lots of queries
Closed, ResolvedPublic

Description

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:

image.png (1,782×754 px, 182 KB)

Another example user who has 820 local accounts had 36% of the request be taken up by checking local blocks which totalled 2 seconds:

image.png (1,311×674 px, 134 KB)

For users who have very few local accounts it takes 4% of the request time:

image.png (1,702×640 px, 233 KB)

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

Event Timeline

OKryva-WMF lowered the priority of this task from High to Medium.Aug 19 2025, 11:18 AM

Change #1184490 had a related patch set uploaded (by STran; author: STran):

[mediawiki/extensions/CentralAuth@master] Instrument CentralAuthUser::getBlocks

https://gerrit.wikimedia.org/r/1184490

Change #1184490 merged by jenkins-bot:

[mediawiki/extensions/CentralAuth@master] Instrument CentralAuthUser::getBlocks

https://gerrit.wikimedia.org/r/1184490

Change #1184546 had a related patch set uploaded (by Dreamy Jazz; author: STran):

[mediawiki/extensions/CentralAuth@wmf/1.45.0-wmf.17] Instrument CentralAuthUser::getBlocks

https://gerrit.wikimedia.org/r/1184546

Change #1184546 merged by jenkins-bot:

[mediawiki/extensions/CentralAuth@wmf/1.45.0-wmf.17] Instrument CentralAuthUser::getBlocks

https://gerrit.wikimedia.org/r/1184546

Mentioned in SAL (#wikimedia-operations) [2025-09-03T15:03:30Z] <dreamyjazz@deploy1003> Started scap sync-world: Backport for [[gerrit:1184546|Instrument CentralAuthUser::getBlocks (T401701)]]

Mentioned in SAL (#wikimedia-operations) [2025-09-03T15:09:48Z] <dreamyjazz@deploy1003> dreamyjazz: Backport for [[gerrit:1184546|Instrument CentralAuthUser::getBlocks (T401701)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2025-09-03T15:15:33Z] <dreamyjazz@deploy1003> Finished scap sync-world: Backport for [[gerrit:1184546|Instrument CentralAuthUser::getBlocks (T401701)]] (duration: 12m 03s)

Change #1184884 had a related patch set uploaded (by STran; author: STran):

[mediawiki/extensions/CentralAuth@master] [WIP] Cache getBlocks()

https://gerrit.wikimedia.org/r/1184884

Change #1184884 merged by jenkins-bot:

[mediawiki/extensions/CentralAuth@master] Cache CentralAuthUser::getBlocks() results where possible

https://gerrit.wikimedia.org/r/1184884

I did a UIC lookup twice for SBassett (WMF). First time CentralAuthUser::getBlocks took 21% of total time (451ms), second it took 5.7% (16ms).

I see a similar thing for other users with lots of cross-wiki activity I have tested.

For the user NguoiDungKhongDinhDanh, the first time I tried to do a UIC lookup it failed (I think due to a timeout). The second time it succeeded but took 3.5 seconds, most of which is due to CheckUserGlobalContributionsLookup::getAndUpdateExternalWikiPermissions (taking 80%+ of the total time). I have retried a few times but it doesn't seem to be cached. @STran is this a known issue? Should I raise it separately?

On the plus side, the getBlocks for that user is taking about 20-30ms.

@dom_walden Is the flaw that CheckUserGlobalContributionsLookup::getAndUpdateExternalWikiPermissions doesn't seem to be caching? I looked at the excimer and it looks like getBlocks is taking 30ms which seems to be in bounds. It would be a new issue in that case, thanks!

@dom_walden Is the flaw that CheckUserGlobalContributionsLookup::getAndUpdateExternalWikiPermissions doesn't seem to be caching? I looked at the excimer and it looks like getBlocks is taking 30ms which seems to be in bounds. It would be a new issue in that case, thanks!

Thanks. I have raised T405559 and I will move this along.