Page MenuHomePhabricator

API initializes user preferences on every request
Closed, ResolvedPublic

Description

ApiMain by default always sets context language to that of user, which involves $user->getOption( 'language' ) which i turn calls User::loadOptions() which calls the UserGetDefaultOptions hook which is handled by many extensions, including the noticeably slow processing by Gadgets. Can the API lazy load it or maybe User can perform a minimal initialization for language only?

Event Timeline

MaxSem raised the priority of this task from to Needs Triage.
MaxSem updated the task description. (Show Details)
MaxSem subscribed.

I had originally wanted uselang=user to not be the default, but lots of people complained.

For User to perform a minimal initialization for language only, we'd basically have to make it so that the UserGetDefaultOptions and UserLoadOptions hooks couldn't affect the language preference. That seems liable to be problematic in the future.

Real lazy loading would also be a bit annoying (we'd either have to implement an ApiDerivativeContext just to override the one method, or find anyone who calls ->getContext() on an API object and fix them), so let's see if they'll let us get away with moving uselang=user into RequestContext itself and have the API just punt on it.

Change 182832 had a related patch set uploaded (by Anomie):
API: Avoid unstubbing User for language pref when not needed

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

Patch-For-Review

Anomie added a project: MediaWiki-Core-Team.
Anomie set Security to None.
Anomie moved this task from Backlog to Needs Review/Feedback on the MediaWiki-Core-Team board.

Change 182832 merged by jenkins-bot:
API: Avoid unstubbing User for language pref when not needed

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