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