r112815 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112814‎ | r112815 | r112816 >
Date:15:52, 1 March 2012
Author:nikerabbit
Status:resolved (Comments)
Tags:
Comment:
Cache metadata to avoid query flood
Modified paths:
  • /trunk/extensions/Translate/utils/TranslateMetadata.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/TranslateMetadata.php
@@ -18,10 +18,19 @@
1919 * @return String
2020 */
2121 public static function get( $group, $key ) {
22 - $dbr = wfGetDB( DB_SLAVE );
23 - $conds = array( 'tmd_group' => $group, 'tmd_key' => $key );
24 - $result = $dbr->selectField( 'translate_metadata', 'tmd_value', $conds, __METHOD__ );
25 - return $result;
 22+ static $cache = null;
 23+ if ( $cache === null ) {
 24+ $dbr = wfGetDB( DB_SLAVE );
 25+ $cache = $dbr->select( 'translate_metadata', '*', array(), __METHOD__ );
 26+ }
 27+
 28+ foreach ( $cache as $row ) {
 29+ if ( $row->tmd_group === $group && $row->tmd_key === $key ) {
 30+ return $row->tmd_value;
 31+ }
 32+ }
 33+
 34+ return false;
2635 }
2736
2837 /**

Sign-offs

UserFlagDate
Amire80inspected21:24, 1 March 2012

Comments

#Comment by Santhosh.thottingal (talk | contribs)   06:10, 2 March 2012

How about cache invalidation, when we set a new value for the group and key?

#Comment by Nikerabbit (talk | contribs)   06:22, 2 March 2012

Good point. It doesn't seem to cause any problems right now, but should be fixed.

Status & tagging log