4 * Show some statistics on the blob_orphans table, created with trackBlobs.php
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.
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.
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
21 * @ingroup Maintenance ExternalStorage
23 require_once( dirname( __FILE__
) . '/../Maintenance.php' );
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";
31 protected function &getDB( $cluster, $groups = array(), $wiki = false ) {
32 $lb = wfGetLBFactory()->getExternalLB( $cluster );
33 return $lb->getConnection( DB_SLAVE
);
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 );
41 $res = $dbr->select( 'blob_orphans', '*', false, __METHOD__
);
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__
);
53 $size = strlen( $blobRow->blob_text
);
55 $hashes[ sha1( $blobRow->blob_text
) ] = true;
56 $maxSize = max( $size, $maxSize );
60 $this->output( "Number of orphans: $num\n" );
62 $this->output( "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" .
63 "Max size: $maxSize\n" .
64 "Number of unique texts: " . count( $hashes ) . "\n" );
69 $maintClass = "OrphanStats";
70 require_once( RUN_MAINTENANCE_IF_MAIN
);