resourceloader: Remove selective build optimisation from getModuleContent()
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 30 Aug 2018 01:42:24 +0000 (02:42 +0100)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 30 Aug 2018 21:02:57 +0000 (21:02 +0000)
commite42837e97753cd5e03a8dbab865c3ca8a6bcfb93
tree1f4cad79e16ea5589d53e292bd4d823780e7c113
parentfede766fe9950e3a036c263bf17d19d31278221c
resourceloader: Remove selective build optimisation from getModuleContent()

This follows 5ddd7f91c7, which factored out response building
from ResourceLoader.php to ResourceLoaderModule::buildContent.
As optimisation, I made this method only return the array keys
needed for the current response; based $context->getOnly().

The reason for this refactoring was the creation of the
'enableModuleContentVersion' option to getVersionHash(), which
would use this method to create a module response, and hash it.

During the implementation of that option, I ran into a problem.
getVersionHash() is called by the startup module for each
registered module, to create the manifest. The context for the
StartupModule request itself has "only=scripts". But, we must
still compute the version hashes for whole modules, not just
their scripts.

I worked around that problem in aac831f9fa by creating a mock
context in getVersionHash() that stubs out the 'only' parameter.

This worked, but made the assumption that the scripts and styles
of a module cannot differ based on the 'only' parameter.
This assumption was wrong, because the 'only' parameter is part
of ResourceLoaderContext and available to all getters to vary on.
Fortunately, the 'enableModuleContentVersion' option is off by
default and nobody currently using it was differing its output
by the 'only' parameter.

I intend to make use of the 'enableModuleContentVersion' option
in StartupModule to fix T201686. And StartupModule outputs a
manifest if the request specifies only=scripts, and outputs
a warning otherwise. As such, it cannot compute its version
if the 'only' parameter is stubbed out.

* Remove the 'only' parameter stubbing.
* Remove the selective building from the buildContent() method.
  This was not very useful because we need to build the whole
  module regardless when computing the version.

As benefit, this means the in-process cache is now shared between
the call from getVersionHash and the call from makeModuleResponse.

Bug: T201686
Change-Id: I8a17888f95f86ac795bc2de43086225b8a8f4b78
includes/resourceloader/ResourceLoaderModule.php
tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php