r29642 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29641‎ | r29642 | r29643 >
Date:07:39, 12 January 2008
Author:aaron
Status:old
Tags:
Comment:
Cache the notice message
Modified paths:
  • /trunk/extensions/ConfirmAccount/ConfirmAccount.i18n.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/ConfirmAccount_body.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/SpecialConfirmAccount.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmAccount/SpecialConfirmAccount.php
@@ -121,23 +121,32 @@
122122 }
123123
124124 function wfConfirmAccountsNotice( $notice ) {
125 - global $wgConfirmAccountNotice, $wgUser;
 125+ global $wgConfirmAccountNotice, $wgUser, $wgMemc;
126126
127127 if( !$wgConfirmAccountNotice || !$wgUser->isAllowed('confirmaccount') )
128128 return true;
 129+ # Check cached results
 130+ $key = wfMemcKey( 'confirmaccount', 'notice' );
 131+ $message = $wgMemc->get( $key );
129132
130 - $dbr = wfGetDB( DB_SLAVE );
131 - $count = $dbr->selectField( 'account_requests', 'COUNT(*)',
132 - array( 'acr_deleted' => 0, 'acr_held IS NULL' ),
133 - __METHOD__ );
134 -
135 - if( !$count )
136 - return true;
 133+ if( !$message ) {
 134+ $dbr = wfGetDB( DB_SLAVE );
 135+ $count = $dbr->selectField( 'account_requests', 'COUNT(*)',
 136+ array( 'acr_deleted' => 0, 'acr_held IS NULL' ),
 137+ __METHOD__ );
137138
138 - wfLoadExtensionMessages( 'ConfirmAccount' );
 139+ if( $count ) {
 140+ wfLoadExtensionMessages( 'ConfirmAccount' );
 141+ $message = '<div id="mw-confirmaccount-msg" class="mw-confirmaccount-bar">' .
 142+ wfMsgExt( 'confirmaccount-newrequests', array('parseinline'), $count ) . '</div>';
 143+ } else {
 144+ $message = '';
 145+ }
 146+ }
 147+ # Cache results
 148+ $wgMemc->set( $key, $message, 3600*24*7 );
139149
140 - $notice .= '<div id="mw-confirmaccount-msg" class="mw-confirmaccount-bar">' .
141 - wfMsgExt( 'confirmaccount-newrequests', array('parseinline'), $count ) . '</div>';
 150+ $notice .= $message;
142151
143152 return true;
144153 }
Index: trunk/extensions/ConfirmAccount/ConfirmAccount_body.php
@@ -379,6 +379,10 @@
380380 ),
381381 __METHOD__
382382 );
 383+ # Clear cache for notice of how many account requests there are
 384+ global $wgMemc;
 385+ $key = wfMemcKey( 'confirmaccount', 'notice' );
 386+ $wgMemc->delete( $key );
383387 # Send confirmation, required!
384388 $result = $this->sendConfirmationMail( $u, $token, $expires );
385389 if( WikiError::isError( $result ) ) {
@@ -1003,6 +1007,10 @@
10041008 'acr_deleted' => 1 ),
10051009 array( 'acr_id' => $this->acrID, 'acr_deleted' => 0 ),
10061010 __METHOD__ );
 1011+ # Clear cache for notice of how many account requests there are
 1012+ global $wgMemc;
 1013+ $key = wfMemcKey( 'confirmaccount', 'notice' );
 1014+ $wgMemc->delete( $key );
10071015
10081016 $this->showSuccess( $this->submitType );
10091017 } else if( $this->submitType == 'accept' ) {
@@ -1144,6 +1152,10 @@
11451153 wfRunHooks( 'AddNewAccount', array( $user ) );
11461154 # OK, now remove the request from the queue
11471155 $dbw->delete( 'account_requests', array('acr_id' => $this->acrID), __METHOD__ );
 1156+ # Clear cache for notice of how many account requests there are
 1157+ global $wgMemc;
 1158+ $key = wfMemcKey( 'confirmaccount', 'notice' );
 1159+ $wgMemc->delete( $key );
11481160 # Delete any attached file. Do not stop the whole process if this fails
11491161 $key = $row->acr_storage_key;
11501162 if( $key ) {
@@ -1229,6 +1241,10 @@
12301242 'acr_comment' => $this->reason ),
12311243 array( 'acr_id' => $this->acrID, 'acr_held IS NULL', 'acr_deleted' => 0 ),
12321244 __METHOD__ );
 1245+ # Clear cache for notice of how many account requests there are
 1246+ global $wgMemc;
 1247+ $key = wfMemcKey( 'confirmaccount', 'notice' );
 1248+ $wgMemc->delete( $key );
12331249 # Do not send multiple times
12341250 if( !$row->acr_held && !($row->acr_deleted && $row->acr_deleted !='f') ) {
12351251 $result = $u->sendMail( wfMsg( 'confirmaccount-email-subj' ),
Index: trunk/extensions/ConfirmAccount/ConfirmAccount.i18n.php
@@ -72,7 +72,7 @@
7373 'requestaccount-loginnotice' => 'To obtain a user account, you must \'\'\'[[Special:RequestAccount|request one]]\'\'\'.',
7474
7575 # Site message for admins
76 - 'confirmaccount-newrequests' => 'There are currently $1 open [[Special:ConfirmAccounts|account requests]] pending.',
 76+ 'confirmaccount-newrequests' => 'There are currently \'\'\'$1\'\'\' open [[Special:ConfirmAccounts|account requests]] pending.',
7777
7878 # Confirm account page
7979 'confirmaccounts' => 'Confirm account requests',

Status & tagging log