User::saveOptions() optimization
authorAntoine Musso <hashar@free.fr>
Wed, 22 May 2013 14:39:31 +0000 (16:39 +0200)
committerTyler Anthony Romeo <tylerromeo@gmail.com>
Fri, 24 Jan 2014 19:09:11 +0000 (11:09 -0800)
commitff355e87e2f7a41a87c37f43232a44113cb033e0
tree5d557acfa26ccd28b8255dd6cfded7c0bfd60d2f
parentc0d3e85b06d628e5c4a7c93cfe5fb7587f9118f0
User::saveOptions() optimization

Since we only want to save non default user options, we have to strip
out any user option that match the default ones. We did that by calling
User::getDefaultOption( 'some option name' ); on each of the option.

Since the User mOptions property is a merge of the default option, we
end up doing a lot of unneeded processing. The loop roughly looks like:

 User::getDefaultOption()
   User::getDefaultOptions()
     Language->getCode()
     SearchEngine::searchableNamespaces()
       language->getNamespaces()
       wfRunHooks('SearcheableNamespaces')
     wfRunHooks('UserGetDefaultOptions')

For EACH of the mOptions.

Instead this patch does an array_diff to strip out from mObjects any
default option.  We still skip options whose value is false or null.

Test provided to make sure we only save what we want.

Change-Id: Ie98d3a17edab74401ed32f759ba11f723b56e376
includes/User.php
tests/phpunit/includes/UserTest.php