r108560 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108559‎ | r108560 | r108561 >
Date:23:12, 10 January 2012
Author:reedy
Status:reverted (Comments)
Tags:
Comment:
Add svn:keywords Id

Trim trailing whitespace

Add explicit member variables
Modified paths:
  • /trunk/phase3/includes/ConcurrencyCheck.php (modified) (history)
  • /trunk/phase3/includes/api/ApiConcurrency.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/ConcurrencyCheckTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/api/ApiConcurrencyTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/ConcurrencyCheckTest.php
@@ -5,9 +5,9 @@
66 * @var Array of test users
77 */
88 public static $users;
9 -
 9+
1010 // Prepare test environment
11 -
 11+
1212 public function setUp() {
1313 parent::setUp();
1414
@@ -25,22 +25,22 @@
2626 array()
2727 ),
2828 );
29 -
 29+
3030 // turn on memcached for this test.
3131 // if no memcached is present, this still works fine.
3232 global $wgMainCacheType;
3333 $this->oldcache = $wgMainCacheType;
3434 $wgMainCacheType = CACHE_MEMCACHED;
3535 }
36 -
 36+
3737 public function tearDown() {
3838 // turn off caching again.
3939 global $wgMainCacheType;
4040 $wgMainCacheType = $this->oldcache;
41 -
42 - parent::tearDown();
 41+
 42+ parent::tearDown();
4343 }
44 -
 44+
4545 // Actual tests from here down
4646
4747 public function testCheckoutCheckin() {
@@ -51,7 +51,7 @@
5252 // clean up after any previously failed tests
5353 $first->checkin($testKey);
5454 $second->checkin($testKey);
55 -
 55+
5656 // tests
5757 $this->assertTrue( $first->checkout($testKey), "Initial checkout" );
5858 $this->assertTrue( $first->checkout($testKey), "Cache hit" );
@@ -77,7 +77,7 @@
7878 $cc->checkout( 1339 );
7979 $cc->setExpirationTime();
8080 $cc->checkout( 13310 );
81 -
 81+
8282 // tests
8383 $this->assertEquals( 2, $cc->expire(), "Resource expiration" );
8484 $this->assertTrue( $cc->checkin( 13310 ), "Checkin succeeds after expiration" );
@@ -99,4 +99,4 @@
100100 $this->assertEquals( 'invalid', $output[1339]['status'], "Expired checkouts are invalid");
101101 $this->assertEquals( 'invalid', $output[13310]['status'], "Missing checkouts are invalid");
102102 }
103 -}
\ No newline at end of file
 103+}
Index: trunk/phase3/tests/phpunit/includes/api/ApiConcurrencyTest.php
@@ -106,7 +106,6 @@
107107
108108 }
109109
110 -
111110 /**
112111 * @depends testLogin
113112 */
@@ -168,4 +167,4 @@
169168
170169 }
171170
172 -}
\ No newline at end of file
 171+}
Index: trunk/phase3/includes/api/ApiConcurrency.php
@@ -4,7 +4,6 @@
55 * API module that handles cooperative locking of web resources
66 */
77 class ApiConcurrency extends ApiBase {
8 -
98 public function __construct( $main, $action ) {
109 parent::__construct( $main, $action );
1110 }
@@ -24,11 +23,10 @@
2524 case 'checkout':
2625 case 'checkin':
2726 if ( $concurrencyCheck->$params['ccaction']( $params['record'] ) ) {
28 - $res['result'] = 'success';
 27+ $res['result'] = 'success';
 28+ } else {
 29+ $res['result'] = 'failure';
2930 }
30 - else {
31 - $res['result'] = 'failure';
32 - }
3331 break;
3432
3533 default:
@@ -92,7 +90,7 @@
9391 }
9492
9593 public function getVersion() {
96 - return __CLASS__ . ': $Id: ApiConcurrency.php $';
 94+ return __CLASS__ . ': $Id$';
9795 }
9896
9997 private function checkPermission( $user ) {
@@ -104,4 +102,4 @@
105103 }
106104 }
107105
108 -}
\ No newline at end of file
 106+}
Property changes on: trunk/phase3/includes/api/ApiConcurrency.php
___________________________________________________________________
Added: svn:keywords
109107 + Id
Index: trunk/phase3/includes/ConcurrencyCheck.php
@@ -18,7 +18,15 @@
1919 * @author Ian Baker <ian@wikimedia.org>
2020 */
2121 class ConcurrencyCheck {
 22+
 23+ protected $expirationTime;
 24+
2225 /**
 26+ * @var User
 27+ */
 28+ protected $user;
 29+
 30+ /**
2331 * Constructor
2432 *
2533 * @var $resourceType String The calling application or type of resource, conceptually like a namespace
@@ -75,7 +83,7 @@
7684 'cc_expiration' => time() + $this->expirationTime,
7785 ),
7886 __METHOD__,
79 - array('IGNORE')
 87+ array( 'IGNORE' )
8088 );
8189
8290 // if the insert succeeded, checkout is done.
@@ -143,7 +151,7 @@
144152 $dbw = $this->dbw;
145153 $userId = $this->user->getId();
146154 $cacheKey = wfMemcKey( $this->resourceType, $record );
147 -
 155+
148156 $dbw->delete(
149157 'concurrencycheck',
150158 array(
@@ -154,14 +162,14 @@
155163 __METHOD__,
156164 array()
157165 );
158 -
 166+
159167 // check row count (this is atomic, select would not be)
160168 if( $dbw->affectedRows() === 1 ) {
161169 $memc->delete( $cacheKey );
162170 return true;
163171 }
164 -
165 - return false;
 172+
 173+ return false;
166174 }
167175
168176 /**
@@ -171,9 +179,9 @@
172180 */
173181 public function expire() {
174182 $memc = wfGetMainCache();
175 - $dbw = $this->dbw;
 183+ $dbw = $this->dbw;
176184 $now = time();
177 -
 185+
178186 // get the rows to remove from cache.
179187 $res = $dbw->select(
180188 'concurrencycheck',
@@ -184,13 +192,13 @@
185193 __METHOD__,
186194 array()
187195 );
188 -
 196+
189197 // build a list of rows to delete.
190198 $toExpire = array();
191199 while( $res && $record = $res->fetchRow() ) {
192200 $toExpire[] = $record['cc_record'];
193201 }
194 -
 202+
195203 // remove the rows from the db
196204 $dbw->delete(
197205 'concurrencycheck',
@@ -200,7 +208,7 @@
201209 __METHOD__,
202210 array()
203211 );
204 -
 212+
205213 // delete all those rows from cache
206214 // outside a transaction because deletes don't require atomicity.
207215 foreach( $toExpire as $expire ) {
@@ -210,7 +218,7 @@
211219 // return the number of rows removed.
212220 return $dbw->affectedRows();
213221 }
214 -
 222+
215223 public function status( $keys ) {
216224 $memc = wfGetMainCache();
217225 $dbw = $this->dbw;
@@ -218,11 +226,11 @@
219227
220228 $checkouts = array();
221229 $toSelect = array();
222 -
 230+
223231 // validate keys, attempt to retrieve from cache.
224232 foreach( $keys as $key ) {
225233 $this->validateId( $key );
226 -
 234+
227235 $cached = $memc->get( wfMemcKey( $this->resourceType, $key ) );
228236 if( $cached && $cached['expiration'] > $now ) {
229237 $checkouts[$key] = array(
@@ -256,11 +264,11 @@
257265 __METHOD__,
258266 array()
259267 );
260 -
 268+
261269 while( $res && $record = $res->fetchRow() ) {
262270 $record['status'] = 'valid';
263271 $checkouts[ $record['cc_record'] ] = $record;
264 -
 272+
265273 // safe to store values since this is inside the transaction
266274 $memc->set(
267275 wfMemcKey( $this->resourceType, $record['cc_record'] ),
@@ -272,7 +280,7 @@
273281 // end the transaction.
274282 $dbw->rollback();
275283 }
276 -
 284+
277285 // if a key was passed in but has no (unexpired) checkout, include it in the
278286 // result set to make things easier and more consistent on the client-side.
279287 foreach( $keys as $key ) {
@@ -280,19 +288,22 @@
281289 $checkouts[$key]['status'] = 'invalid';
282290 }
283291 }
284 -
 292+
285293 return $checkouts;
286294 }
287 -
 295+
288296 public function listCheckouts() {
289297 // TODO: fill in the function that lets you get the complete set of checkouts for a given application.
290298 }
291 -
292 - public function setUser ( $user ) {
 299+
 300+ /**
 301+ * @param $user user
 302+ */
 303+ public function setUser( $user ) {
293304 $this->user = $user;
294305 }
295 -
296 - public function setExpirationTime ( $expirationTime = null ) {
 306+
 307+ public function setExpirationTime( $expirationTime = null ) {
297308 global $wgConcurrencyExpirationDefault, $wgConcurrencyExpirationMax, $wgConcurrencyExpirationMin;
298309
299310 // check to make sure the time is digits only, so it can be used in queries
@@ -321,10 +332,10 @@
322333 if( ! preg_match('/^\d+$/', $record) ) {
323334 throw new ConcurrencyCheckBadRecordIdException( 'Record ID ' . $record . ' must be a positive integer' );
324335 }
325 -
 336+
326337 // TODO: add a hook here for client-side validation.
327338 return true;
328339 }
329340 }
330341
331 -class ConcurrencyCheckBadRecordIdException extends MWException {};
 342+class ConcurrencyCheckBadRecordIdException extends MWException {}

Follow-up revisions

RevisionCommit summaryAuthorDate
r108601reverts Concurrency works...hashar09:05, 11 January 2012

Comments

#Comment by Hashar (talk | contribs)   09:07, 11 January 2012

Reverted by r108601 . Manually added as a followup.

Status & tagging log