r79390 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79389‎ | r79390 | r79391 >
Date:00:03, 1 January 2011
Author:reedy
Status:ok
Tags:
Comment:
More refactoring and fixing for bug 23720
Modified paths:
  • /trunk/extensions/CodeReview/backend/CodeRevision.php (modified) (history)
  • /trunk/extensions/CodeReview/repopulateCodePaths.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/backend/CodeRevision.php
@@ -77,16 +77,18 @@
7878 */
7979 public static function getPathFragments( $paths = array() ) {
8080 $allPaths = array();
81 - $path = "/";
82 - foreach( $paths as $partPath ) {
8381
84 - if ( $path !== "/" ) {
85 - $path .= '/';
86 - }
 82+ foreach( $paths as $path ) {
 83+ $currentPath = "/";
 84+ foreach( explode( '/', $path['path'] ) as $fragment ) {
 85+ if ( $currentPath !== "/" ) {
 86+ $currentPath .= '/';
 87+ }
8788
88 - $path .= $partPath;
 89+ $currentPath .= $fragment;
8990
90 - $allPaths[] = $path;
 91+ $allPaths[] = array( 'path' => $currentPath, 'action' => $path['action'] ) ;
 92+ }
9193 }
9294
9395 return array_unique( $allPaths );
@@ -288,7 +290,7 @@
289291 * @param array $options
290292 * @return void
291293 */
292 - protected function insertChunks( $db, $table, $data, $method = __METHOD__, $options = array() ) {
 294+ protected static function insertChunks( $db, $table, $data, $method = __METHOD__, $options = array() ) {
293295 $chunkSize = 100;
294296 for ( $i = 0; $i < count( $data ); $i += $chunkSize ) {
295297 $db->insert( $table,
@@ -338,15 +340,7 @@
339341
340342 // Update path tracking used for output and searching
341343 if ( $this->mPaths ) {
342 - $data = array();
343 - foreach ( $this->mPaths as $path ) {
344 - $data[] = array(
345 - 'cp_repo_id' => $this->mRepoId,
346 - 'cp_rev_id' => $this->mId,
347 - 'cp_path' => $path['path'],
348 - 'cp_action' => $path['action'] );
349 - }
350 - $this->insertChunks( $dbw, 'code_paths', $data, __METHOD__, array( 'IGNORE' ) );
 344+ CodeRevision::insertPaths( $dbw, $this->mPaths, $this->mRepoId, $this->mId );
351345 }
352346
353347 $affectedRevs = $this->getUniqueAffectedRevs();
@@ -418,6 +412,18 @@
419413 $dbw->commit();
420414 }
421415
 416+ public static function insertPaths( $dbw, $paths, $repoId, $revId ) {
 417+ $data = array();
 418+ foreach ( $paths as $path ) {
 419+ $data[] = array(
 420+ 'cp_repo_id' => $repoId,
 421+ 'cp_rev_id' => $revid,
 422+ 'cp_path' => $path['path'],
 423+ 'cp_action' => $path['action'] );
 424+ }
 425+ self::insertChunks( $dbw, 'code_paths', $data, __METHOD__, array( 'IGNORE' ) );
 426+ }
 427+
422428 /**
423429 * Returns a unique value array from that of getAffectedRevs() and getAffectedBugRevs()
424430 *
Index: trunk/extensions/CodeReview/repopulateCodePaths.php
@@ -44,36 +44,21 @@
4545
4646 $data = array();
4747 foreach ( $res as $row ) {
48 - $fragments = CodeRevision::getPathFragments( array( $row->cp_path ) );
49 - $this->output( "r{$row->cp_rev_id}, path: " . $row->cp_path . " Fragments: " . count( $fragments ) );
 48+ $data = array_merge(CodeRevision::getPathFragments(
 49+ array( 'path' => $row->cp_path, 'action' => $row->cp_action ) ) );
5050
51 - $data[] = array(
52 - 'cp_repo_id' => $repo->getId(),
53 - 'cp_rev_id' => $row->cp_rev_id,
54 - 'cp_path' => $fragments,
55 - 'cp_action' => $row->cp_action
56 - );
 51+ $this->output( "r{$row->cp_rev_id}, path: " . $row->cp_path . " Fragments: " .
 52+ count( $fragments ) . "\n" );
5753 }
5854
5955 $dbw = wfGetDB( DB_MASTER );
6056 $dbw->begin();
6157 $this->output( "Commiting paths...\n" );
62 - $this->insertChunks( $dbw, 'code_paths', $data, __METHOD__, array( 'IGNORE' ) );
63 - $dbw->commit();
 58+ CodeRevision::insertPaths( $dbw, $data, $repo->getId(), $row->cp_rev_id );
 59+ $dbw->commit();
6460
6561 $this->output( "Done!\n" );
6662 }
67 -
68 - private static function insertChunks( $db, $table, $data, $method = __METHOD__, $options = array() ) {
69 - $chunkSize = 100;
70 - for ( $i = 0; $i < count( $data ); $i += $chunkSize ) {
71 - $db->insert( $table,
72 - array_slice( $data, $i, $chunkSize ),
73 - $method,
74 - $options
75 - );
76 - }
77 - }
7863 }
7964
8065 $maintClass = "RepopulateCodePaths";

Follow-up revisions

RevisionCommit summaryAuthorDate
r79391Fix tab fail, tweak messages...reedy00:07, 1 January 2011
r79401Minor extra bit for bug 23720, remove performance restrictionreedy01:12, 1 January 2011
r81038(bug 23720) CodeReview doesn't show ancient revisions for a path...reedy17:27, 26 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79379*(bug 23720) CodeReview doesn't show ancient revisions for a path...reedy22:55, 31 December 2010
r79381More for bug 23720....reedy23:02, 31 December 2010
r79384Add repopuldateCodePaths maintenance script for bug 23720 (untested, will be ...reedy23:32, 31 December 2010

Status & tagging log