Index: trunk/extensions/ShortUrl/populateShortUrlTable.php |
— | — | @@ -26,31 +26,42 @@ |
27 | 27 | public function execute() { |
28 | 28 | $rowCount = 0; |
29 | 29 | $dbr = wfGetDB( DB_SLAVE ); |
30 | | - $res = $dbr->select( |
31 | | - 'page', |
32 | | - array( 'page_namespace', 'page_title' ), |
33 | | - array(), |
34 | | - __METHOD__ |
35 | | - ); |
| 30 | + |
| 31 | + $last_processed_id = 0; |
| 32 | + |
36 | 33 | $insertBuffer = array(); |
37 | 34 | |
38 | | - foreach( $res as $row ) { |
39 | | - $rowData = array( |
40 | | - 'su_namespace' => $row->page_namespace, |
41 | | - 'su_title' => $row->page_title |
| 35 | + while( true ) { |
| 36 | + $res = $dbr->select( |
| 37 | + 'page', |
| 38 | + array( 'page_id', 'page_namespace', 'page_title' ), |
| 39 | + array( "page_id > " . $last_processed_id ), |
| 40 | + __METHOD__, |
| 41 | + array( 'LIMIT' => 100 ) |
42 | 42 | ); |
43 | | - array_push( $insertBuffer, $rowData ); |
44 | | - if( count( $insertBuffer ) % 100 == 0 ) { |
45 | | - $this->insertRows( $insertBuffer ); |
46 | | - $insertBuffer = array(); |
| 43 | + if( $res->numRows() == 0 ) { |
| 44 | + break; |
| 45 | + } |
| 46 | + |
| 47 | + foreach( $res as $row ) { |
| 48 | + $rowCount++; |
| 49 | + |
| 50 | + $rowData = array( |
| 51 | + 'su_namespace' => $row->page_namespace, |
| 52 | + 'su_title' => $row->page_title |
| 53 | + ); |
| 54 | + $this->output( $insertBuffer ); |
| 55 | + array_push( $insertBuffer, $rowData ); |
| 56 | + |
| 57 | + $last_processed_id = $row->page_id; |
47 | 58 | } |
48 | | - $this->output( $rowCount . " titles done\n" ); |
49 | 59 | |
50 | | - $rowCount++; |
51 | | - } |
52 | | - if( count( $insertBuffer ) > 0 ) { |
53 | 60 | $this->insertRows( $insertBuffer ); |
| 61 | + $insertBuffer = array(); |
| 62 | + wfWaitForSlaves(); // 'Kill' lag |
| 63 | + $this->output( $rowCount . " titles done\n" ); |
54 | 64 | } |
| 65 | + $this->output( "Done\n" ); |
55 | 66 | } |
56 | 67 | } |
57 | 68 | |