Bartosz Dziewoński has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/391037 )

Change subject: Preferences: Remove unwise caching of 
Preferences::getPreferences()
......................................................................

Preferences: Remove unwise caching of Preferences::getPreferences()

The result of this function depends on the $user and $context
parameters (e.g. it includes the username from the user, and
localisation messages the language from the context). However,
both of them would be ignored if the result was cached, even
if calling with a different $user or $context.

Rather than make this more complicated just remove the caching.
This is not a hot code path: this function is not called at all
on normal page views, it's called just once when viewing
preferences, and at most twice when saving them.

Change-Id: I92390120a16448383a25e9ba2dd35a434a2f21bf
---
M includes/Preferences.php
M tests/phpunit/includes/PreferencesTest.php
2 files changed, 2 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/37/391037/1

diff --git a/includes/Preferences.php b/includes/Preferences.php
index 738f8ee..e383f03 100644
--- a/includes/Preferences.php
+++ b/includes/Preferences.php
@@ -48,9 +48,6 @@
  */
 class Preferences {
        /** @var array */
-       protected static $defaultPreferences = null;
-
-       /** @var array */
        protected static $saveFilters = [
                'timecorrection' => [ 'Preferences', 'filterTimezoneInput' ],
                'rclimit' => [ 'Preferences', 'filterIntval' ],
@@ -78,10 +75,6 @@
         * @return array|null
         */
        static function getPreferences( $user, IContextSource $context ) {
-               if ( self::$defaultPreferences ) {
-                       return self::$defaultPreferences;
-               }
-
                OutputPage::setupOOUI(
                        strtolower( $context->getSkin()->getSkinName() ),
                        $context->getLanguage()->getDir()
@@ -103,7 +96,6 @@
                Hooks::run( 'GetPreferences', [ $user, &$defaultPreferences ] );
 
                self::loadPreferenceValues( $user, $context, 
$defaultPreferences );
-               self::$defaultPreferences = $defaultPreferences;
                return $defaultPreferences;
        }
 
diff --git a/tests/phpunit/includes/PreferencesTest.php 
b/tests/phpunit/includes/PreferencesTest.php
index b25e046..4a15225 100644
--- a/tests/phpunit/includes/PreferencesTest.php
+++ b/tests/phpunit/includes/PreferencesTest.php
@@ -150,20 +150,9 @@
 
        /** Helper */
        protected function prefsFor( $user_key ) {
-               // TODO This should use Preferences::getPreferences() instead 
of calling internal methods.
-               // Unfortunately that currently ignores the $user parameter if 
it has cached data, even for
-               // a different user...
-               OutputPage::setupOOUI(
-                       strtolower( $this->context->getSkin()->getSkinName() ),
-                       $this->context->getLanguage()->getDir()
-               );
-               $preferences = [];
-               Preferences::profilePreferences(
+               return Preferences::getPreferences(
                        $this->prefUsers[$user_key],
-                       $this->context,
-                       $preferences
+                       $this->context
                );
-
-               return $preferences;
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/391037
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I92390120a16448383a25e9ba2dd35a434a2f21bf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to