r54945 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54944‎ | r54945 | r54946 >
Date:16:32, 13 August 2009
Author:catrope
Status:deferred
Tags:
Comment:
LocalisationUpdate: SCHEMA CHANGE: Address FIXME from r54936 by recording the last fetch timestamp in the localisation_file_hash table and using the MAX of that for l10n_cache invalidation, and fix a selectField() call where select() was intended. Making a whitespace change in LocalisationUpdate.i18n.php so the previous version of the dependency object doesn't get stuck in l10n cache
Modified paths:
  • /trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php (modified) (history)
  • /trunk/extensions/LocalisationUpdate/LocalisationUpdate.i18n.php (modified) (history)
  • /trunk/extensions/LocalisationUpdate/patch-lfh_timestamp.sql (added) (history)
  • /trunk/extensions/LocalisationUpdate/schema.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/LocalisationUpdate/patch-lfh_timestamp.sql
@@ -0,0 +1,4 @@
 2+-- Patch that adds lfh_timestamp field and index
 3+
 4+ALTER TABLE /*_*/localisation_file_hash ADD lfh_timestamp varchar(14) NOT NULL;
 5+CREATE INDEX /*i*/lfh_timestamp ON /*_*/localisation_file_hash (lfh_timestamp);
Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.i18n.php
@@ -5,7 +5,7 @@
66 * @file
77 * @ingroup Extensions
88 */
9 -
 9+
1010 $messages = array();
1111
1212 /** English
Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php
@@ -5,7 +5,7 @@
66 $dbr = wfGetDB ( DB_SLAVE );
77
88 // Get the messages from the database
9 - $res = $dbr->selectField( 'localisation',
 9+ $res = $dbr->select( 'localisation',
1010 array( 'lo_key', 'lo_value' ),
1111 array( 'lo_language' => $langcode ),
1212 __METHOD__ );
@@ -236,12 +236,12 @@
237237 $changedStrings = array_diff_assoc( $base_messages, $compare_messages );
238238
239239 // If we want to save the differences
240 - if ( $saveResults === true && !empty($changedStrings) && is_array($changedStrings)) {
 240+ if ( $saveResults && !empty($changedStrings) && is_array($changedStrings)) {
241241 self::myLog( "--Checking languagecode {$langcode}--" );
242242 // The save them
243243 $updates = self::saveChanges( $changedStrings, $forbiddenKeys, $base_messages, $langcode, $verbose );
244244 self::myLog( "{$updates} messages updated for {$langcode}." );
245 - } elseif($saveResults === true) {
 245+ } elseif ( $saveResults ) {
246246 self::myLog( "--{$langcode} hasn't changed--" );
247247 }
248248
@@ -257,6 +257,13 @@
258258 return $changedStrings;
259259 }
260260
 261+ /**
 262+ * Checks whether a messages file has a certain hash
 263+ * TODO: Swap return values, this is insane
 264+ * @param $file string Filename
 265+ * @param $hash string Hash
 266+ * @return bool True if $file does NOT have hash $hash, false if it does
 267+ */
261268 public static function checkHash( $file, $hash ) {
262269 $db = wfGetDB( DB_MASTER );
263270
@@ -271,10 +278,15 @@
272279
273280 public static function saveHash ($file, $hash) {
274281 $db = wfGetDB ( DB_MASTER );
275 - $hashConds = array( 'lfh_file' => $file, 'lfh_hash' => $hash );
276 - $conds = array( 'lfh_file' => $file );
277 - $db->delete( 'localisation_file_hash', $conds , __METHOD__ );
278 - $db->insert( 'localisation_file_hash', $hashConds, __METHOD__ );
 282+ // Double query sucks but we wanna make sure we don't update
 283+ // the timestamp when the hash hasn't changed
 284+ if ( self::checkHash( $file, $hash ) )
 285+ $db->replace( 'localisation_file_hash', array( 'lfh_file' ), array(
 286+ 'lfh_file' => $file,
 287+ 'lfh_hash' => $hash,
 288+ 'lfh_timestamp' => $db->timestamp( wfTimestamp() )
 289+ ), __METHOD__
 290+ );
279291 }
280292
281293 public static function saveChanges( $changedStrings, $forbiddenKeys, $base_messages, $langcode, $verbose ) {
@@ -458,9 +470,10 @@
459471 }
460472
461473 public static function schemaUpdates() {
462 - global $wgExtNewTables;
 474+ global $wgExtNewTables, $wgExtNewFields;
463475 $dir = dirname( __FILE__ );
464476 $wgExtNewTables[] = array( 'localisation', "$dir/schema.sql" );
 477+ $wgExtNewFields[] = array( 'localisation_file_hash', 'lfh_timestamp', "$dir/patch-lfh_timestamp.sql" );
465478 return true;
466479 }
467480
@@ -480,32 +493,26 @@
481494 }
482495
483496 class LUDependency extends CacheDependency {
484 - var $hashes;
 497+ var $timestamp;
485498
486499 function isExpired() {
487 - # FIXME: make this faster by changing the schema to include a last update timestamp
488 - $hashes = $this->getHashesFromDB();
489 - return $hashes !== $this->hashes;
 500+ $timestamp = $this->getTimestamp();
 501+ return $timestamp !== $this->timestamp;
490502 }
491503
492504 function loadDependencyValues() {
493 - $this->hashes = $this->getHashesFromDB();
 505+ $this->timestamp = $this->getTimestamp();
494506 }
495507
496 - function getHashesFromDB() {
 508+ function getTimestamp() {
497509 $dbr = wfGetDB( DB_SLAVE );
498 - $res = $dbr->select(
499 - 'localisation_file_hash', '*', false, __METHOD__,
500 - array( 'ORDER BY' => 'lfh_file' ) );
501 - $hashes = '';
502 - foreach ( $res as $row ) {
503 - $hashes .= "{$row->lfh_file} {$row->lfh_hash}\n";
504 - }
505 - return $hashes;
 510+ return $dbr->selectField(
 511+ 'localisation_file_hash', 'MAX(lfh_timestamp)', '',
 512+ __METHOD__ );
506513 }
507514
508515 function __sleep() {
509516 $this->loadDependencyValues();
510 - return array( 'hashes' );
 517+ return array( 'timestamp' );
511518 }
512519 }
Index: trunk/extensions/LocalisationUpdate/schema.sql
@@ -9,10 +9,13 @@
1010
1111 CREATE TABLE /*$wgDBprefix*/localisation_file_hash (
1212 lfh_file varchar(250) NOT NULL,
13 - lfh_hash varchar(50) NOT NULL
 13+ lfh_hash varchar(50) NOT NULL,
 14+ lfh_timestamp varchar(14) NOT NULL
1415 ) /*$wgDBTableOptions*/;
1516
1617 CREATE UNIQUE INDEX /*i*/lfh_file ON
1718 /*$wgDBprefix*/localisation_file_hash (lfh_file);
1819 CREATE INDEX /*i*/lfh_file_hash ON
19 - /*$wgDBprefix*/localisation_file_hash (lfh_file, lfh_hash);
\ No newline at end of file
 20+ /*$wgDBprefix*/localisation_file_hash (lfh_file, lfh_hash);
 21+CREATE INDEX /*i*/lfh_timestamp ON
 22+ /*$wgDBprefix*/localisation_file_hash (lfh_timestamp);
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r54936Simplistic reorganisation for compatibility with r52503. Load messages pre-ca...tstarling14:16, 13 August 2009

Status & tagging log