00001 <?php
00002
00006 require_once( dirname(__FILE__).'/../commandLine.inc' );
00007
00008 $stats = new OrphanStats;
00009 $stats->execute();
00010
00011 class OrphanStats {
00012 function getDB( $cluster ) {
00013 $lb = wfGetLBFactory()->getExternalLB( $cluster );
00014 return $lb->getConnection( DB_SLAVE );
00015 }
00016
00017 function execute() {
00018 $extDBs = array();
00019 $dbr = wfGetDB( DB_SLAVE );
00020 $res = $dbr->select( 'blob_orphans', '*', false, __METHOD__ );
00021
00022 $num = 0;
00023 $totalSize = 0;
00024 $hashes = array();
00025 $maxSize = 0;
00026
00027 foreach ( $res as $boRow ) {
00028 $extDB = $this->getDB( $boRow->bo_cluster );
00029 $blobRow = $extDB->selectRow( 'blobs', '*', array( 'blob_id' => $boRow->bo_blob_id ), __METHOD__ );
00030
00031 $num++;
00032 $size = strlen( $blobRow->blob_text );
00033 $totalSize += $size;
00034 $hashes[ sha1( $blobRow->blob_text ) ] = true;
00035 $maxSize = max( $size, $maxSize );
00036 }
00037 unset( $res );
00038
00039 echo "Number of orphans: $num\n";
00040 if ( $num > 0 ) {
00041 echo "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" .
00042 "Max size: $maxSize\n" .
00043 "Number of unique texts: " . count( $hashes ) . "\n";
00044 }
00045 }
00046 }