https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112815

Revision: 112815
Author:   nikerabbit
Date:     2012-03-01 15:52:45 +0000 (Thu, 01 Mar 2012)
Log Message:
-----------
Cache metadata to avoid query flood

Modified Paths:
--------------
    trunk/extensions/Translate/utils/TranslateMetadata.php

Modified: trunk/extensions/Translate/utils/TranslateMetadata.php
===================================================================
--- trunk/extensions/Translate/utils/TranslateMetadata.php      2012-03-01 
15:28:04 UTC (rev 112814)
+++ trunk/extensions/Translate/utils/TranslateMetadata.php      2012-03-01 
15:52:45 UTC (rev 112815)
@@ -18,10 +18,19 @@
         * @return String
         */
        public static function get( $group, $key ) {
-               $dbr = wfGetDB( DB_SLAVE );
-               $conds = array( 'tmd_group' => $group, 'tmd_key' => $key );
-               $result = $dbr->selectField( 'translate_metadata', 'tmd_value', 
$conds, __METHOD__ );
-               return $result;
+               static $cache = null;
+               if ( $cache === null ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $cache = $dbr->select( 'translate_metadata', '*', 
array(), __METHOD__ );
+               }
+
+               foreach ( $cache as $row ) {
+                       if ( $row->tmd_group === $group && $row->tmd_key === 
$key ) {
+                               return $row->tmd_value;
+                       }
+               }
+
+               return false;
        }
 
        /**


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to