MediaWiki  REL1_24
orphanStats.php
Go to the documentation of this file.
00001 <?php
00024 require_once __DIR__ . '/../Maintenance.php';
00025 
00032 class OrphanStats extends Maintenance {
00033     public function __construct() {
00034         parent::__construct();
00035         $this->mDescription =
00036             "Show some statistics on the blob_orphans table, created with trackBlobs.php";
00037     }
00038 
00039     protected function &getDB( $cluster, $groups = array(), $wiki = false ) {
00040         $lb = wfGetLBFactory()->getExternalLB( $cluster );
00041 
00042         return $lb->getConnection( DB_SLAVE );
00043     }
00044 
00045     public function execute() {
00046         $dbr = wfGetDB( DB_SLAVE );
00047         if ( !$dbr->tableExists( 'blob_orphans' ) ) {
00048             $this->error( "blob_orphans doesn't seem to exist, need to run trackBlobs.php first", true );
00049         }
00050         $res = $dbr->select( 'blob_orphans', '*', false, __METHOD__ );
00051 
00052         $num = 0;
00053         $totalSize = 0;
00054         $hashes = array();
00055         $maxSize = 0;
00056 
00057         foreach ( $res as $boRow ) {
00058             $extDB = $this->getDB( $boRow->bo_cluster );
00059             $blobRow = $extDB->selectRow(
00060                 'blobs',
00061                 '*',
00062                 array( 'blob_id' => $boRow->bo_blob_id ),
00063                 __METHOD__
00064             );
00065 
00066             $num++;
00067             $size = strlen( $blobRow->blob_text );
00068             $totalSize += $size;
00069             $hashes[sha1( $blobRow->blob_text )] = true;
00070             $maxSize = max( $size, $maxSize );
00071         }
00072         unset( $res );
00073 
00074         $this->output( "Number of orphans: $num\n" );
00075         if ( $num > 0 ) {
00076             $this->output( "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" .
00077                 "Max size: $maxSize\n" .
00078                 "Number of unique texts: " . count( $hashes ) . "\n" );
00079         }
00080     }
00081 }
00082 
00083 $maintClass = "OrphanStats";
00084 require_once RUN_MAINTENANCE_IF_MAIN;