r84435 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84434‎ | r84435 | r84436 >
Date:00:10, 21 March 2011
Author:aaron
Status:ok
Tags:
Comment:
Timeout/locking fixes for r84383 (these don't do anything yet though anyway)
Modified paths:
  • /trunk/extensions/FlaggedRevs/FRUserActivity.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FRUserActivity.php
@@ -64,24 +64,35 @@
6565 global $wgMemc;
6666 $key = wfMemcKey( 'flaggedrevs', 'userReviewingPage', $pageId );
6767 $val = array( $user->getName(), wfTimestampNow() );
 68+ $wasSet = false;
 69+
 70+ $wgMemc->lock( $key, 4 ); // 4 sec timeout
6871 if ( !$wgMemc->get( $key ) ) { // no flag set
69 - # Set the flag (use locks if available)
70 - $wgMemc->lock( $key, 4000 ); // 4 sec timeout
7172 $wgMemc->set( $key, $val, 20*60 ); // 20 min
72 - $wgMemc->unlock( $key );
73 - return true;
 73+ $wasSet = true;
7474 }
75 - return false;
 75+ $wgMemc->unlock( $key );
 76+
 77+ return $wasSet;
7678 }
7779
7880 /*
7981 * Clear the flag for who is reviewing a page
 82+ * @param User $user
8083 * @param int $pageId
8184 */
82 - public static function clearUserReviewingPage( $pageId ) {
 85+ public static function clearUserReviewingPage( $user, $pageId ) {
8386 global $wgMemc;
8487 $key = wfMemcKey( 'flaggedrevs', 'userReviewingPage', $pageId );
85 - $wgMemc->delete( $key );
 88+ $wgMemc->lock( $key, 4 ); // 4 sec timeout
 89+ $val = $wgMemc->get( $key );
 90+ if ( is_array( $val ) && count( $val ) == 2 ) { // flag set
 91+ list( $u, $ts ) = $val;
 92+ if ( $u === $user->getName() ) {
 93+ $wgMemc->delete( $key );
 94+ }
 95+ }
 96+ $this->unlock();
8697 }
8798
8899 /*
@@ -110,23 +121,35 @@
111122 global $wgMemc;
112123 $key = wfMemcKey( 'flaggedrevs', 'userReviewingDiff', $oldId, $newId );
113124 $val = array( $user->getName(), wfTimestampNow() );
 125+ $wasSet = false;
 126+
 127+ $wgMemc->lock( $key, 4 ); // 4 sec timeout
114128 if ( !$wgMemc->get( $key ) ) { // no flag set
115 - # Set the flag (use locks if available)
116 - $wgMemc->lock( $key, 4000 ); // 4 sec timeout
117129 $wgMemc->set( $key, $val, 6*20 ); // 6 min
118 - $wgMemc->unlock( $key );
119 - return true;
 130+ $wasSet = true;
120131 }
121 - return false;
 132+ $wgMemc->unlock( $key );
 133+
 134+ return $wasSet;
122135 }
123136
124137 /*
125138 * Clear the flag for who is reviewing a diff
126 - * @param int $pageId
 139+ * @param User $user
 140+ * @param int $oldId
 141+ * @param int $newId
127142 */
128 - public static function clearUserReviewingDiff( $oldId, $newId ) {
 143+ public static function clearUserReviewingDiff( $user, $oldId, $newId ) {
129144 global $wgMemc;
130145 $key = wfMemcKey( 'flaggedrevs', 'userReviewingDiff', $oldId, $newId );
131 - $wgMemc->delete( $key );
 146+ $wgMemc->lock( $key, 4 ); // 4 sec timeout
 147+ $val = $wgMemc->get( $key );
 148+ if ( is_array( $val ) && count( $val ) == 2 ) { // flag set
 149+ list( $u, $ts ) = $val;
 150+ if ( $u === $user->getName() ) {
 151+ $wgMemc->delete( $key );
 152+ }
 153+ }
 154+ $this->unlock();
132155 }
133156 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84383* Moved "users watching"/"user currently reviewing" functions to FRUserActivi...aaron14:42, 20 March 2011

Status & tagging log