Index: trunk/phase3/maintenance/archives/patch-ar_sha1.sql |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +-- Adding ar_sha1 field |
| 3 | +ALTER TABLE /*$wgDBprefix*/archive |
| 4 | + ADD ar_sha1 varbinary(32) NOT NULL default ''; |
Property changes on: trunk/phase3/maintenance/archives/patch-ar_sha1.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 5 | + native |
Index: trunk/phase3/maintenance/archives/patch-rev_sha1.sql |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +-- Adding rev_sha1 field |
| 3 | +ALTER TABLE /*$wgDBprefix*/revision |
| 4 | + ADD rev_sha1 varbinary(32) NOT NULL default ''; |
Property changes on: trunk/phase3/maintenance/archives/patch-rev_sha1.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 5 | + native |
Index: trunk/phase3/maintenance/populateRevisionSha1.php |
— | — | @@ -0,0 +1,96 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Fills the rev_sha1 and ar_sha1 columns of revision & archive tables. |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along |
| 17 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + * http://www.gnu.org/copyleft/gpl.html |
| 20 | + * |
| 21 | + * @ingroup Maintenance |
| 22 | + */ |
| 23 | + |
| 24 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 25 | + |
| 26 | +class PopulateRevisionSha1 extends Maintenance { |
| 27 | + public function __construct() { |
| 28 | + parent::__construct(); |
| 29 | + $this->mDescription = "Populates the rev_sha1 and ar_sha1 fields"; |
| 30 | + $this->setBatchSize( 150 ); |
| 31 | + } |
| 32 | + |
| 33 | + public function execute() { |
| 34 | + $db = wfGetDB( DB_MASTER ); |
| 35 | + |
| 36 | + $this->output( "Populating rev_len column\n" ); |
| 37 | + $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' ); |
| 38 | + |
| 39 | + $this->output( "Populating ar_len column\n" ); |
| 40 | + $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' ); |
| 41 | + |
| 42 | + if ( $db->insert( |
| 43 | + 'updatelog', |
| 44 | + array( 'ul_key' => 'populate rev_sha1' ), |
| 45 | + __METHOD__, |
| 46 | + 'IGNORE' |
| 47 | + ) |
| 48 | + ) { |
| 49 | + $this->output( "rev_sha1 and ar_sha1 population complete.\n" ); |
| 50 | + return true; |
| 51 | + } else { |
| 52 | + $this->output( "Could not insert rev_sha1 population row.\n" ); |
| 53 | + return false; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + protected function doSha1Updates( $db, $table, $idCol, $prefix ) { |
| 58 | + $start = $db->selectField( $table, "MIN($idCol)", "$idCol IS NOT NULL", __METHOD__ ); |
| 59 | + if ( !$start ) { |
| 60 | + $this->output( "Nothing to do.\n" ); |
| 61 | + return true; |
| 62 | + } |
| 63 | + $end = $db->selectField( $table, "MAX($idCol)", "$idCol IS NOT NULL", __METHOD__ ); |
| 64 | + |
| 65 | + # Do remaining chunk |
| 66 | + $end += $this->mBatchSize - 1; |
| 67 | + $blockStart = $start; |
| 68 | + $blockEnd = $start + $this->mBatchSize - 1; |
| 69 | + while ( $blockEnd <= $end ) { |
| 70 | + $this->output( "...doing $idCol from $blockStart to $blockEnd\n" ); |
| 71 | + $cond = "$idCol BETWEEN $blockStart AND $blockEnd |
| 72 | + AND $idCol IS NOT NULL AND {$prefix}_sha1 IS NOT NULL"; |
| 73 | + $res = $db->select( $table, '*', $cond, __METHOD__ ); |
| 74 | + |
| 75 | + $db->begin(); |
| 76 | + foreach ( $res as $row ) { |
| 77 | + if ( $table === 'archive' ) { |
| 78 | + $rev = Revision::newFromArchiveRow( $row ); |
| 79 | + } else { |
| 80 | + $rev = new Revision( $row ); |
| 81 | + } |
| 82 | + $db->update( $table, |
| 83 | + array( "{$prefix}_sha1" => Revision::base36Sha1( $rev->getRawText() ) ), |
| 84 | + array( $idCol => $row->$idCol ), |
| 85 | + __METHOD__ ); |
| 86 | + } |
| 87 | + $db->commit(); |
| 88 | + |
| 89 | + $blockStart += $this->mBatchSize; |
| 90 | + $blockEnd += $this->mBatchSize; |
| 91 | + wfWaitForSlaves(); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +$maintClass = "PopulateRevisionSha1"; |
| 97 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/phase3/maintenance/populateRevisionSha1.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 98 | + native |
Index: trunk/phase3/maintenance/tables.sql |
— | — | @@ -317,8 +317,11 @@ |
318 | 318 | |
319 | 319 | -- Key to revision.rev_id |
320 | 320 | -- This field is used to add support for a tree structure (The Adjacency List Model) |
321 | | - rev_parent_id int unsigned default NULL |
| 321 | + rev_parent_id int unsigned default NULL, |
322 | 322 | |
| 323 | + -- SHA-1 text content hash in base-36 |
| 324 | + rev_sha1 varbinary(32) NOT NULL default '' |
| 325 | + |
323 | 326 | ) /*$wgDBTableOptions*/ MAX_ROWS=10000000 AVG_ROW_LENGTH=1024; |
324 | 327 | -- In case tables are created as MyISAM, use row hints for MySQL <5.0 to avoid 4GB limit |
325 | 328 | |
— | — | @@ -424,7 +427,10 @@ |
425 | 428 | ar_page_id int unsigned, |
426 | 429 | |
427 | 430 | -- Original previous revision |
428 | | - ar_parent_id int unsigned default NULL |
| 431 | + ar_parent_id int unsigned default NULL, |
| 432 | + |
| 433 | + -- SHA-1 text content hash in base-36 |
| 434 | + ar_sha1 varbinary(32) NOT NULL default '' |
429 | 435 | ) /*$wgDBTableOptions*/; |
430 | 436 | |
431 | 437 | CREATE INDEX /*i*/name_title_timestamp ON /*_*/archive (ar_namespace,ar_title,ar_timestamp); |
Index: trunk/phase3/includes/installer/MysqlUpdater.php |
— | — | @@ -186,6 +186,9 @@ |
187 | 187 | // 1.19 |
188 | 188 | array( 'addTable', 'config', 'patch-config.sql' ), |
189 | 189 | array( 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql'), |
| 190 | + array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ), |
| 191 | + array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' ), |
| 192 | + array( 'doPopulateRevSha1' ) |
190 | 193 | ); |
191 | 194 | } |
192 | 195 | |
— | — | @@ -855,4 +858,14 @@ |
856 | 859 | $this->applyPatch( 'patch-user-newtalk-timestamp-null.sql' ); |
857 | 860 | $this->output( "done.\n" ); |
858 | 861 | } |
| 862 | + |
| 863 | + protected function doPopulateRevSha1() { |
| 864 | + if ( $this->updateRowExists( 'populate rev_sha1' ) ) { |
| 865 | + $this->output( "...rev_sha1/ar_sha1 columns already populated.\n" ); |
| 866 | + return; |
| 867 | + } |
| 868 | + |
| 869 | + $task = $this->maintenance->runChild( 'PopulateRevisionSha1' ); |
| 870 | + $task->execute(); |
| 871 | + } |
859 | 872 | } |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -838,6 +838,7 @@ |
839 | 839 | 'PopulateLogUsertext' => 'maintenance/populateLogUsertext.php', |
840 | 840 | 'PopulateParentId' => 'maintenance/populateParentId.php', |
841 | 841 | 'PopulateRevisionLength' => 'maintenance/populateRevisionLength.php', |
| 842 | + 'PopulateRevisionSha1' => 'maintenance/PopulateRevisionSha1.php', |
842 | 843 | 'SevenZipStream' => 'maintenance/7zip.inc', |
843 | 844 | 'Sqlite' => 'maintenance/sqlite.inc', |
844 | 845 | 'UpdateCollation' => 'maintenance/updateCollation.php', |