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