r54936 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54935‎ | r54936 | r54937 >
Date:14:16, 13 August 2009
Author:tstarling
Status:deferred
Tags:
Comment:
Simplistic reorganisation for compatibility with r52503. Load messages pre-cache to avoid DB queries on wfMsg(). Still needs some optimisation work.
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
@@ -22,9 +22,12 @@
2323 );
2424
2525 // Use the right hook
26 -$wgHooks['MessageNotInMwNs'][] = "LocalisationUpdate::FindUpdatedMessage";
 26+$wgHooks['LocalisationCacheRecache'][] = 'LocalisationUpdate::onRecache'; // MW 1.16+
2727
2828 $dir = dirname( __FILE__ ) . '/';
2929 $wgExtensionMessagesFiles['LocalisationUpdate'] = $dir . 'LocalisationUpdate.i18n.php';
3030 $wgAutoloadClasses['LocalisationUpdate'] = $dir . 'LocalisationUpdate.class.php';
 31+$wgAutoloadClasses['LUDependency'] = $dir . 'LocalisationUpdate.class.php';
 32+
3133 $wgHooks['LoadExtensionSchemaUpdates'][] = 'LocalisationUpdate::schemaUpdates';
 34+
Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php
@@ -1,31 +1,19 @@
22 <?php
33 class LocalisationUpdate {
44 // DB Search funtion
5 - public static function FindUpdatedMessage( &$message, $lckey, $langcode, $isFullKey ) {
6 - // Define a cache
7 - static $cache = array();
8 - $db = wfGetDB ( DB_SLAVE );
 5+ public static function onRecache( $lc, $code, &$data ) {
 6+ $dbr = wfGetDB ( DB_SLAVE );
97
10 - // If the key also contains the language code remove the language code from the key
11 - if ( $isFullKey ) {
12 - $lckey = preg_replace( "/\/" . $langcode . "/", "", $lckey );
13 - }
 8+ // Get the messages from the database
 9+ $res = $dbr->selectField( 'localisation',
 10+ array( 'lo_key', 'lo_value' ),
 11+ array( 'lo_language' => $langcode ),
 12+ __METHOD__ );
1413
15 - // If message is in the cache, don't get an update!
16 - if ( array_key_exists( $lckey . "/" . $langcode, $cache ) ) {
17 - $message = $cache[$lckey . "/" . $langcode];
18 - return true;
 14+ foreach ( $res as $row ) {
 15+ $cache['messages'][$row->lo_key] = $row->lo_value;
1916 }
20 -
21 - // Get the message from the database
22 - $conds = array( 'lo_key' => $lckey, 'lo_language' => $langcode );
23 - $result = $db->selectField( 'localisation', 'lo_value', $conds, __METHOD__ ); // Check if the database has any updated message
24 - if ( $result === false ) { // If no results found, exit here
25 - return true;
26 - }
27 -
28 - $message = $result;
29 - $cache[$lckey . "/" . $langcode] = $result; // Update the cache
 17+ $cache['deps'][] = new LUDependency;
3018 return true;
3119 }
3220
@@ -489,5 +477,35 @@
490478 $vars = $ce->getVars();
491479 return @$vars[$varname];
492480 }
 481+}
493482
494 -}
\ No newline at end of file
 483+class LUDependency extends CacheDependency {
 484+ var $hashes;
 485+
 486+ 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;
 490+ }
 491+
 492+ function loadDependencyValues() {
 493+ $this->hashes = $this->getHashesFromDB();
 494+ }
 495+
 496+ function getHashesFromDB() {
 497+ $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;
 506+ }
 507+
 508+ function __sleep() {
 509+ $this->loadDependencyValues();
 510+ return array( 'hashes' );
 511+ }
 512+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r54938LocalisationUpdate: Fix undefined variables in r54936catrope14:29, 13 August 2009
r54945LocalisationUpdate: SCHEMA CHANGE: Address FIXME from r54936 by recording the...catrope16:32, 13 August 2009
r55275LocalisationUpdate: Make LU compatible with 1.15 and below by re-adding the M...catrope21:33, 18 August 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r52503* Introduced a new system for localisation caching. The system is based aroun...tstarling07:11, 28 June 2009

Status & tagging log