r56784 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56783‎ | r56784 | r56785 >
Date:20:13, 22 September 2009
Author:brion
Status:resolved (Comments)
Tags:
Comment:
Add $wgLocalisationUpdateDatabase config var to pull from a central database.
To keep things simple this will need to pull from on the primary database connection
rather than add another connection dependency; so for instance on Wikimedia we'll want
one wiki in each cluster that holds the updated localisation tables.
Modified paths:
  • /trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php (modified) (history)
  • /trunk/extensions/LocalisationUpdate/LocalisationUpdate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.php
@@ -21,6 +21,18 @@
2222
2323 $wgLocalisationUpdateRetryAttempts = 5;
2424
 25+/**
 26+ * If you want to share LocalisationUpdate info between multiple wikis,
 27+ * you can have them reference a central copy of the tables in a given
 28+ * database. Must be accessible via the main database connection.
 29+ *
 30+ * Note that if your wikis have different extensions enabled, you may
 31+ * wish to pass the --all option to LocalisationUpdate/update.php so it
 32+ * pulls updates for all extensions present in the source tree instead
 33+ * of just the ones you have enabled on the wiki you run it from.
 34+ */
 35+$wgLocalisationUpdateDatabase = false;
 36+
2537 // Info about me!
2638 $wgExtensionCredits['other'][] = array(
2739 'path' => __FILE__,
Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php
@@ -20,7 +20,7 @@
2121
2222 // Get the message from the database
2323 $conds = array( 'lo_key' => $lckey, 'lo_language' => $langcode );
24 - $result = $db->selectField( 'localisation', 'lo_value', $conds, __METHOD__ ); // Check if the database has any updated message
 24+ $result = $db->selectField( self::table( 'localisation' ), 'lo_value', $conds, __METHOD__ ); // Check if the database has any updated message
2525 if ( $result === false ) { // If no results found, exit here
2626 return true;
2727 }
@@ -35,7 +35,7 @@
3636 $dbr = wfGetDB ( DB_SLAVE );
3737
3838 // Get the messages from the database
39 - $res = $dbr->select( 'localisation',
 39+ $res = $dbr->select( self::table( 'localisation' ),
4040 array( 'lo_key', 'lo_value' ),
4141 array( 'lo_language' => $langcode ),
4242 __METHOD__ );
@@ -279,7 +279,7 @@
280280 // Add the messages we got with our previous update(s) to the local array (as we already got these as well)
281281 $fields = array( 'lo_key', 'lo_value' );
282282 $conds = array( 'lo_language' => $langcode );
283 - $result = $db->select( 'localisation', $fields, $conds, __METHOD__ );
 283+ $result = $db->select( self::table( 'localisation' ), $fields, $conds, __METHOD__ );
284284 foreach ( $result as $r ) {
285285 $compare_messages[$r->lo_key] = $r->lo_value;
286286 }
@@ -316,7 +316,7 @@
317317 $db = wfGetDB( DB_MASTER );
318318
319319 $hashConds = array( 'lfh_file' => $file, 'lfh_hash' => $hash );
320 - $result = $db->select( 'localisation_file_hash', '*', $hashConds, __METHOD__ );
 320+ $result = $db->select( self::table( 'localisation_file_hash' ), '*', $hashConds, __METHOD__ );
321321 if ( $db->numRows( $result ) == 0 ) {
322322 return true;
323323 } else {
@@ -329,7 +329,7 @@
330330 // Double query sucks but we wanna make sure we don't update
331331 // the timestamp when the hash hasn't changed
332332 if ( self::checkHash( $file, $hash ) )
333 - $db->replace( 'localisation_file_hash', array( 'lfh_file' ), array(
 333+ $db->replace( self::table( 'localisation_file_hash' ), array( 'lfh_file' ), array(
334334 'lfh_file' => $file,
335335 'lfh_hash' => $hash,
336336 'lfh_timestamp' => $db->timestamp( wfTimestamp() )
@@ -358,7 +358,7 @@
359359 'lo_language' => $langcode,
360360 'lo_key' => $key
361361 );
362 - $db->replace( 'localisation',
 362+ $db->replace( self::table( 'localisation' ),
363363 array( 'PRIMARY' ), $values,
364364 __METHOD__ );
365365
@@ -479,7 +479,7 @@
480480 // Add the already known messages to the array so we will only find new changes
481481 $fields = array( 'lo_key', 'lo_value' );
482482 $conds = array( 'lo_language' => $language );
483 - $result = $db->select( 'localisation', $fields, $conds, __METHOD__ );
 483+ $result = $db->select( self::table( 'localisation' ), $fields, $conds, __METHOD__ );
484484 foreach ( $result as $r ) {
485485 $compare_messages[$r->lo_key] = $r->lo_value;
486486 }
@@ -544,6 +544,15 @@
545545 return false;
546546 }
547547 }
 548+
 549+ public static function table( $table ) {
 550+ global $wgLocalisationUpdateDatabase;
 551+ if( $wgLocalisationUpdateDatabase ) {
 552+ return "$wgLocalisationUpdateDatabase.$table";
 553+ } else {
 554+ return $table;
 555+ }
 556+ }
548557 }
549558
550559 class LUDependency extends CacheDependency {
@@ -561,7 +570,9 @@
562571 function getTimestamp() {
563572 $dbr = wfGetDB( DB_SLAVE );
564573 return $dbr->selectField(
565 - 'localisation_file_hash', 'MAX(lfh_timestamp)', '',
 574+ LocalisationUpdate::table( 'localisation_file_hash' ),
 575+ 'MAX(lfh_timestamp)',
 576+ '',
566577 __METHOD__ );
567578 }
568579

Follow-up revisions

RevisionCommit summaryAuthorDate
r56788Merge r56784 updates for multi-db accessbrion21:27, 22 September 2009

Comments

#Comment by Tim Starling (talk | contribs)   02:30, 2 December 2009

Using database selectors in a write query may break replication, if replicate_do_db, replicate_ignore_db, etc. are used. Please wrap the write queries with $db->selectDB() instead.

#Comment by Tim Starling (talk | contribs)   22:53, 3 February 2010

The code was removed in r56831, marking resolved.

Status & tagging log