resourceloader: Omit getDirection() ResourceLoaderContext hash
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 17 Nov 2015 21:11:19 +0000 (21:11 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 17 Nov 2015 21:38:33 +0000 (21:38 +0000)
The direction is derived from the language code, which is included
already. The method was added for convenience to consuming code,
but including it in the cache key seems pointless.

Main rationale here is runtime performance. getDirection() incurs
Language::factory() and Language::getDir() which require loading
of LCStore files.

Change-Id: I397a1c483203ec2c4903046c9494cae1c9480f8c

includes/resourceloader/ResourceLoaderContext.php
tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php

index 6c4cdfe..6ecee4c 100644 (file)
@@ -333,12 +333,20 @@ class ResourceLoaderContext {
        }
 
        /**
+        * All factors that uniquely identify this request, except 'modules'.
+        *
+        * The list of modules is excluded here for legacy reasons as most callers already
+        * split up handling of individual modules. Including it here would massively fragment
+        * the cache and decrease its usefulness.
+        *
+        * E.g. Used by RequestFileCache to form a cache key for storing the reponse output.
+        *
         * @return string
         */
        public function getHash() {
                if ( !isset( $this->hash ) ) {
                        $this->hash = implode( '|', array(
-                               $this->getLanguage(), $this->getDirection(), $this->getSkin(), $this->getUser(),
+                               $this->getLanguage(), $this->getSkin(), $this->getUser(),
                                $this->getImage(), $this->getVariant(), $this->getFormat(),
                                $this->getDebug(), $this->getOnly(), $this->getVersion()
                        ) );
index 0d11f62..b457cec 100644 (file)
@@ -25,7 +25,7 @@ class DerivativeResourceLoaderContextTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals( $derived->getModules(), array( 'test.context' ) );
                $this->assertEquals( $derived->getOnly(), 'scripts' );
                $this->assertEquals( $derived->getSkin(), 'fallback' );
-               $this->assertEquals( $derived->getHash(), 'zh|ltr|fallback||||||scripts|' );
+               $this->assertEquals( $derived->getHash(), 'zh|fallback||||||scripts|' );
        }
 
        public function testSetLanguage() {
@@ -72,7 +72,7 @@ class DerivativeResourceLoaderContextTest extends PHPUnit_Framework_TestCase {
 
                $derived->setLanguage( 'nl' );
                // Assert that subclass is able to clear parent class "hash" member
-               $this->assertEquals( $derived->getHash(), 'nl|ltr|fallback||||||scripts|' );
+               $this->assertEquals( $derived->getHash(), 'nl|fallback||||||scripts|' );
        }
 
 }