jenkins-bot has submitted this change and it was merged.
Change subject: ResourceLoaderSchemaModule: Use definition hash instead of fake
timestamp
......................................................................
ResourceLoaderSchemaModule: Use definition hash instead of fake timestamp
Remove old unit tests since this behaviour is already tested in
MediaWiki core. I kept the test for returning a bottom timestamp
of 1 in case we can't fetch the schema.
Bug: T94059
Change-Id: I26f9ab09fc7ee1e5330315f7b9e3d290eff5d79f
---
M includes/ResourceLoaderSchemaModule.php
M tests/ResourceLoaderSchemaModuleTest.php
2 files changed, 21 insertions(+), 78 deletions(-)
Approvals:
Ori.livneh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/ResourceLoaderSchemaModule.php
b/includes/ResourceLoaderSchemaModule.php
index 88fd46f..1c79af4 100644
--- a/includes/ResourceLoaderSchemaModule.php
+++ b/includes/ResourceLoaderSchemaModule.php
@@ -67,31 +67,34 @@
/**
- * Gets the last modified timestamp of this module.
+ * Get the last modified timestamp of this module.
+ *
* The last modified timestamp controls caching. Because revisions are
- * immutable, we don't need to get the revision's timestamp. We
- * simply return a timestamp of 1 (one second past epoch) if we were
- * unable to retrieve the schema, or the revision id if successful.
- * This ensures that clients will retrieve the schema when it becomes
- * available.
+ * immutable, we don't need to fetch the RemoteSchema, nor get the
revision's
+ * timestamp. We simply hash our module definition.
+ *
* @param ResourceLoaderContext $context
* @return integer: Unix timestamp.
*/
function getModifiedTime( ResourceLoaderContext $context ) {
- global $wgCacheEpoch;
-
- $unixTimeCacheEpoch = wfTimestamp( TS_UNIX, $wgCacheEpoch );
- if ( $this->schema->get() ) {
- // ResourceLoader will set the module's modification
time to be
- // either the value returned by this method, or the
Unix time
- // number of $wgCacheEpoch, whichever is greater. To
ensure that
- // the modification time is always updated whenever the
schema
- // revision changes, we add the revision ID to the Unix
time number
- // of $wgCacheEpoch.
- return $unixTimeCacheEpoch + $this->schema->revision;
- } else {
+ if ( !$this->schema->get() ) {
+ // If we failed to fetch, hold off on rolling over
definition timestamp
return 1;
}
+ return $this->getDefinitionMtime( $context );
+ }
+
+ /**
+ * Get the definition summary for this module.
+ *
+ * @param ResourceLoaderContext $context
+ * @return array
+ */
+ public function getDefinitionSummary( ResourceLoaderContext $context ) {
+ return array(
+ 'class' => get_class( $this ),
+ 'revision' => $this->schema->revision,
+ );
}
diff --git a/tests/ResourceLoaderSchemaModuleTest.php
b/tests/ResourceLoaderSchemaModuleTest.php
index cf163e8..e298e72 100644
--- a/tests/ResourceLoaderSchemaModuleTest.php
+++ b/tests/ResourceLoaderSchemaModuleTest.php
@@ -50,22 +50,6 @@
/**
- * When the RemoteSchema dependency cannot be loaded, the modified
- * time should be set to 1.
- * @covers ResourceLoaderSchemaModule::getModifiedTime
- */
- function testFetchFailureModifiedTime() {
- $this->module->schema
- ->expects( $this->once() )
- ->method( 'get' )
- ->will( $this->returnValue( false ) );
-
- $mtime = $this->module->getModifiedTime( $this->context );
- $this->assertEquals( self::ERROR_VERSION, $mtime );
- }
-
-
- /**
* When the RemoteSchema dependency can be loaded, the modified time
* should be set to sum of $wgCacheEpoch (in UNIX time) and the
revision number.
* @covers ResourceLoaderSchemaModule::getModifiedTime
@@ -94,50 +78,6 @@
$unixTimeCacheEpoch,
$mtime,
'Should be greater than cache epoch, so epoch does not
mask updates'
- );
- }
-
- /*
- Gets the effective modification time, as calculated by
- ResourceLoaderStartupModule. It calculates this as the maximum of
- the module's self-reported modification time and $wgCacheEpoch.
-
- This is not broken into a method in core, so we reproduce it here.
- */
- function getEffectiveModifiedTime( $module) {
- global $wgCacheEpoch;
-
- $moduleMtime = wfTimestamp( TS_UNIX, $module->getModifiedTime(
$this->context ) );
- $mtime = max( $moduleMtime, wfTimestamp( TS_UNIX, $wgCacheEpoch
) );
- return $mtime;
- }
-
- /**
- * When a schema is updated, the effective ModifiedTime as calculated
by ResourceLoader
- * should increase.
- */
- function testEffectiveModifiedTimeIncreases() {
- $oldSchemaContent = array( 'numberOfGrains' => array( 'type' =>
'integer' ) );
- $newSchemaContent = array( 'grainCount' => array( 'type' =>
'integer' ) );
-
- $oldModule = $this->getMockSchemaModule( self::TITLE, 123 );
- $oldModule->schema
- ->expects( $this->once() )
- ->method( 'get' )
- ->will( $this->returnValue( $oldSchemaContent ) );
- $oldEffectiveModifiedTime = $this->getEffectiveModifiedTime(
$oldModule );
-
- $newModule = $this->getMockSchemaModule( self::TITLE, 124 );
- $newModule->schema
- ->expects( $this->once() )
- ->method( 'get' )
- ->will( $this->returnValue( $newSchemaContent ) );
- $newEffectiveModifiedTime = $this->getEffectiveModifiedTime(
$newModule );
-
- $this->assertGreaterThan(
- $oldEffectiveModifiedTime,
- $newEffectiveModifiedTime,
- 'A schema with a newer revid should have a greater
effective modified time.'
);
}
--
To view, visit https://gerrit.wikimedia.org/r/200028
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I26f9ab09fc7ee1e5330315f7b9e3d290eff5d79f
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/EventLogging
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits