Index: trunk/extensions/CodeReview/backend/CodeRevision.php |
— | — | @@ -77,16 +77,18 @@ |
78 | 78 | */ |
79 | 79 | public static function getPathFragments( $paths = array() ) { |
80 | 80 | $allPaths = array(); |
81 | | - $path = "/"; |
82 | | - foreach( $paths as $partPath ) { |
83 | 81 | |
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 | + } |
87 | 88 | |
88 | | - $path .= $partPath; |
| 89 | + $currentPath .= $fragment; |
89 | 90 | |
90 | | - $allPaths[] = $path; |
| 91 | + $allPaths[] = array( 'path' => $currentPath, 'action' => $path['action'] ) ; |
| 92 | + } |
91 | 93 | } |
92 | 94 | |
93 | 95 | return array_unique( $allPaths ); |
— | — | @@ -288,7 +290,7 @@ |
289 | 291 | * @param array $options |
290 | 292 | * @return void |
291 | 293 | */ |
292 | | - protected function insertChunks( $db, $table, $data, $method = __METHOD__, $options = array() ) { |
| 294 | + protected static function insertChunks( $db, $table, $data, $method = __METHOD__, $options = array() ) { |
293 | 295 | $chunkSize = 100; |
294 | 296 | for ( $i = 0; $i < count( $data ); $i += $chunkSize ) { |
295 | 297 | $db->insert( $table, |
— | — | @@ -338,15 +340,7 @@ |
339 | 341 | |
340 | 342 | // Update path tracking used for output and searching |
341 | 343 | 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 ); |
351 | 345 | } |
352 | 346 | |
353 | 347 | $affectedRevs = $this->getUniqueAffectedRevs(); |
— | — | @@ -418,6 +412,18 @@ |
419 | 413 | $dbw->commit(); |
420 | 414 | } |
421 | 415 | |
| 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 | + |
422 | 428 | /** |
423 | 429 | * Returns a unique value array from that of getAffectedRevs() and getAffectedBugRevs() |
424 | 430 | * |
Index: trunk/extensions/CodeReview/repopulateCodePaths.php |
— | — | @@ -44,36 +44,21 @@ |
45 | 45 | |
46 | 46 | $data = array(); |
47 | 47 | 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 ) ) ); |
50 | 50 | |
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" ); |
57 | 53 | } |
58 | 54 | |
59 | 55 | $dbw = wfGetDB( DB_MASTER ); |
60 | 56 | $dbw->begin(); |
61 | 57 | $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(); |
64 | 60 | |
65 | 61 | $this->output( "Done!\n" ); |
66 | 62 | } |
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 | | - } |
78 | 63 | } |
79 | 64 | |
80 | 65 | $maintClass = "RepopulateCodePaths"; |