]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/storage/orphanStats.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / maintenance / storage / orphanStats.php
1 <?php
2
3 /**
4  * Show some statistics on the blob_orphans table, created with trackBlobs.php
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 ExternalStorage
22  */
23 require_once( dirname( __FILE__ ) . '/../Maintenance.php' );
24
25 class OrphanStats extends Maintenance {
26         public function __construct() {
27                 parent::__construct();
28                 $this->mDescription = "how some statistics on the blob_orphans table, created with trackBlobs.php";
29         }
30
31         private function getDB( $cluster ) {
32                 $lb = wfGetLBFactory()->getExternalLB( $cluster );
33                 return $lb->getConnection( DB_SLAVE );
34         }
35
36         public function execute() {
37                 $dbr = wfGetDB( DB_SLAVE );
38                 if ( !$dbr->tableExists( 'blob_orphans' ) ) {
39                         $this->error( "blob_orphans doesn't seem to exist, need to run trackBlobs.php first", true );
40                 }
41                 $res = $dbr->select( 'blob_orphans', '*', false, __METHOD__ );
42
43                 $num = 0;
44                 $totalSize = 0;
45                 $hashes = array();
46                 $maxSize = 0;
47
48                 foreach ( $res as $boRow ) {
49                         $extDB = $this->getDB( $boRow->bo_cluster );
50                         $blobRow = $extDB->selectRow( 'blobs', '*', array( 'blob_id' => $boRow->bo_blob_id ), __METHOD__ );
51
52                         $num++;
53                         $size = strlen( $blobRow->blob_text );
54                         $totalSize += $size;
55                         $hashes[ sha1( $blobRow->blob_text ) ] = true;
56                         $maxSize = max( $size, $maxSize );
57                 }
58                 unset( $res );
59
60                 $this->output( "Number of orphans: $num\n" );
61                 if ( $num > 0 ) {
62                         $this->output( "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" .
63                         "Max size: $maxSize\n" .
64                         "Number of unique texts: " . count( $hashes ) . "\n" );
65                 }
66         }
67 }
68
69 $maintClass = "OrphanStats";
70 require_once( RUN_MAINTENANCE_IF_MAIN );