Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/251656
Change subject: [WIP] resourceloader: Remove msg_resource_links
......................................................................
[WIP] resourceloader: Remove msg_resource_links
This table is not needed because module names and their messages
array are available to the runtime environment at very little cost.
The only purpose it was serving is reverse lookup from message
key to module name (e.g. when MessageCache receives update that
need to propagate to MessageBlobStore). However that is better
achieved by simply looping through modules in PHP. The overhead
of MySQL is not worth it.
MessageBlobStore
* insertMessageBlob: Doesn't need to update msg_resource_links.
* updateModule: Doesn't need to update msg_resource_links.
* getUpdatesForMessage: Reimplement with list from memory
instead of msg_resource_links.
Bug: T113092
Change-Id: Ia9131f570001f00c9800b260ac4b3469d54d2784
---
M includes/cache/MessageBlobStore.php
M includes/cache/MessageCache.php
M includes/resourceloader/ResourceLoader.php
M maintenance/cleanupRemovedModules.php
M maintenance/tables.sql
M tests/parser/parserTest.inc
6 files changed, 59 insertions(+), 85 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/56/251656/1
diff --git a/includes/cache/MessageBlobStore.php
b/includes/cache/MessageBlobStore.php
index 6290eae..ab7e171 100644
--- a/includes/cache/MessageBlobStore.php
+++ b/includes/cache/MessageBlobStore.php
@@ -41,6 +41,16 @@
*/
protected $blobCache = array();
+ /* @var ResourceLoader */
+ protected $resourceloader;
+
+ /**
+ * @param ResourceLoader $resourceloader
+ */
+ public function __construct( ResourceLoader $resourceloader = null ) {
+ $this->resourceloader = $resourceloader;
+ }
+
/**
* Get the singleton instance
*
@@ -131,29 +141,14 @@
array( 'IGNORE' )
);
- if ( $success ) {
- if ( $dbw->affectedRows() == 0 ) {
- // Blob was already present, fetch it
- $blob = $dbw->selectField(
'msg_resource', 'mr_blob', array(
- 'mr_resource' => $name,
- 'mr_lang' => $lang,
- ),
- __METHOD__
- );
- } else {
- // Update msg_resource_links
- $rows = array();
-
- foreach ( $module->getMessages() as
$key ) {
- $rows[] = array(
- 'mrl_resource' => $name,
- 'mrl_message' => $key
- );
- }
- $dbw->insert( 'msg_resource_links',
$rows,
- __METHOD__, array( 'IGNORE' )
- );
- }
+ if ( $success && $dbw->affectedRows() == 0 ) {
+ // Blob was already present, fetch it
+ $blob = $dbw->selectField( 'msg_resource',
'mr_blob', array(
+ 'mr_resource' => $name,
+ 'mr_lang' => $lang,
+ ),
+ __METHOD__
+ );
}
} catch ( DBError $e ) {
wfDebug( __METHOD__ . " failed to update DB: $e\n" );
@@ -180,8 +175,6 @@
return null;
}
- // Save the old and new blobs for later
- $oldBlob = $row->mr_blob;
$newBlob = $this->generateMessageBlob( $module, $lang );
try {
@@ -196,36 +189,6 @@
array( array( 'mr_resource', 'mr_lang' ) ),
$newRow, __METHOD__
);
-
- // Figure out which messages were added and removed
- $oldMessages = array_keys( FormatJson::decode(
$oldBlob, true ) );
- $newMessages = array_keys( FormatJson::decode(
$newBlob, true ) );
- $added = array_diff( $newMessages, $oldMessages );
- $removed = array_diff( $oldMessages, $newMessages );
-
- // Delete removed messages, insert added ones
- if ( $removed ) {
- $dbw->delete( 'msg_resource_links', array(
- 'mrl_resource' => $name,
- 'mrl_message' => $removed
- ), __METHOD__
- );
- }
-
- $newLinksRows = array();
-
- foreach ( $added as $message ) {
- $newLinksRows[] = array(
- 'mrl_resource' => $name,
- 'mrl_message' => $message
- );
- }
-
- if ( $newLinksRows ) {
- $dbw->insert( 'msg_resource_links',
$newLinksRows, __METHOD__,
- array( 'IGNORE' ) // just in case
- );
- }
} catch ( Exception $e ) {
wfDebug( __METHOD__ . " failed to update DB: $e\n" );
}
@@ -273,24 +236,34 @@
}
} while ( count( $updates ) );
- // No need to update msg_resource_links because we
didn't add
- // or remove any messages, we just changed their
contents.
} catch ( Exception $e ) {
wfDebug( __METHOD__ . " failed to update DB: $e\n" );
}
}
public function clear() {
- // TODO: Give this some more thought
try {
// Not using TRUNCATE, because that needs extra
permissions,
// which maybe not granted to the database user.
$dbw = wfGetDB( DB_MASTER );
$dbw->delete( 'msg_resource', '*', __METHOD__ );
- $dbw->delete( 'msg_resource_links', '*', __METHOD__ );
} catch ( Exception $e ) {
wfDebug( __METHOD__ . " failed to update DB: $e\n" );
}
+ }
+
+ /**
+ * @return ResourceLoader
+ */
+ protected function getResourceLoader() {
+ // For back-compat this class supports instantiation without
passing ResourceLoader
+ // Lazy-initialise this property because most callers don't
need it.
+ if ( $this->resourceloader === null ) {
+ wfDebug( __CLASS__ . ' created without a ResourceLoader
instance' );
+ $this->resourceloader = new ResourceLoader();
+ }
+
+ return $this->resourceloader;
}
/**
@@ -304,11 +277,15 @@
$dbw = wfGetDB( DB_MASTER );
if ( is_null( $prevUpdates ) ) {
+ $rl = $this->getResourceLoader();
+ $moduleNames = $rl->getModulesByMessage( $key );
// Fetch all blobs referencing $key
$res = $dbw->select(
- array( 'msg_resource', 'msg_resource_links' ),
+ array( 'msg_resource' ),
array( 'mr_resource', 'mr_lang', 'mr_blob',
'mr_timestamp' ),
- array( 'mrl_message' => $key,
'mr_resource=mrl_resource' ),
+ array(
+ 'mr_resource' => $moduleNames,
+ ),
__METHOD__
);
} else {
diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php
index ae746e3..bf44e88 100644
--- a/includes/cache/MessageCache.php
+++ b/includes/cache/MessageCache.php
@@ -578,7 +578,8 @@
}
// Update the message in the message blob store
- $blobStore = new MessageBlobStore();
+ $resourceloader =
RequestContext::getMain()->getOutput()->getResourceLoader()
+ $blobStore = $resourceloader->getMessageBlobStore();
$blobStore->updateMessage( $wgContLang->lcfirst( $msg ) );
Hooks::run( 'MessageCacheReplace', array( $title, $text ) );
diff --git a/includes/resourceloader/ResourceLoader.php
b/includes/resourceloader/ResourceLoader.php
index d9416e4..6995642 100644
--- a/includes/resourceloader/ResourceLoader.php
+++ b/includes/resourceloader/ResourceLoader.php
@@ -274,7 +274,7 @@
$this->registerTestModules();
}
- $this->setMessageBlobStore( new MessageBlobStore() );
+ $this->setMessageBlobStore( new MessageBlobStore( $this ) );
}
/**
@@ -1069,6 +1069,23 @@
return $out;
}
+ /**
+ * Get names of modules that use a certain message.
+ *
+ * @param string $messageKey
+ * @return array List of module names
+ */
+ public function getModulesByMessage( $messageKey ) {
+ $moduleNames = array();
+ foreach ( $this->getModuleNames() as $moduleName ) {
+ $module = $this->getModule( $moduleName );
+ if ( in_array( $messageKey, $module->getMessages() ) ) {
+ $moduleNames[] = $moduleName;
+ }
+ }
+ return $moduleNames;
+ }
+
/* Static Methods */
/**
diff --git a/maintenance/cleanupRemovedModules.php
b/maintenance/cleanupRemovedModules.php
index a4e66ca..ae05930 100644
--- a/maintenance/cleanupRemovedModules.php
+++ b/maintenance/cleanupRemovedModules.php
@@ -72,19 +72,6 @@
wfWaitForSlaves();
} while ( $numRows > 0 );
$this->output( "done\n" );
-
- $this->output( "Cleaning up msg_resource_links table...\n" );
- $i = 1;
- $msgResLinks = $dbw->tableName( 'msg_resource_links' );
- do {
- $where = $moduleList ? "mrl_resource NOT IN
($moduleList)" : '1=1';
- $dbw->query( "DELETE FROM $msgResLinks WHERE $where
LIMIT $limit", __METHOD__ );
- $numRows = $dbw->affectedRows();
- $this->output( "Batch $i: $numRows rows\n" );
- $i++;
- wfWaitForSlaves();
- } while ( $numRows > 0 );
- $this->output( "done\n" );
}
}
diff --git a/maintenance/tables.sql b/maintenance/tables.sql
index 35e7ec2..3f143b2 100644
--- a/maintenance/tables.sql
+++ b/maintenance/tables.sql
@@ -1509,14 +1509,6 @@
) /*$wgDBTableOptions*/;
CREATE UNIQUE INDEX /*i*/mr_resource_lang ON /*_*/msg_resource (mr_resource,
mr_lang);
--- Table for administering which message is contained in which resource
-CREATE TABLE /*_*/msg_resource_links (
- mrl_resource varbinary(255) NOT NULL,
- -- Message key
- mrl_message varbinary(255) NOT NULL
-) /*$wgDBTableOptions*/;
-CREATE UNIQUE INDEX /*i*/mrl_message_resource ON /*_*/msg_resource_links
(mrl_message, mrl_resource);
-
-- Table caching which local files a module depends on that aren't
-- registered directly, used for fast retrieval of file dependency.
-- Currently only used for tracking images that CSS depends on
diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc
index 005ade5..faa3ad7 100644
--- a/tests/parser/parserTest.inc
+++ b/tests/parser/parserTest.inc
@@ -964,7 +964,7 @@
'site_stats', 'ipblocks', 'image', 'oldimage',
'recentchanges', 'watchlist', 'interwiki', 'logging',
'querycache', 'objectcache', 'job', 'l10n_cache',
'redirect', 'querycachetwo',
- 'archive', 'user_groups', 'page_props', 'category',
'msg_resource', 'msg_resource_links'
+ 'archive', 'user_groups', 'page_props', 'category',
'msg_resource'
);
if ( in_array( $this->db->getType(), array( 'mysql', 'sqlite',
'oracle' ) ) ) {
--
To view, visit https://gerrit.wikimedia.org/r/251656
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia9131f570001f00c9800b260ac4b3469d54d2784
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits