MediaWiki REL1_30
orphanStats.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/../Maintenance.php';
25
32class OrphanStats extends Maintenance {
33 public function __construct() {
34 parent::__construct();
35 $this->addDescription(
36 "Show some statistics on the blob_orphans table, created with trackBlobs.php" );
37 }
38
39 protected function &getDB( $cluster, $groups = [], $wiki = false ) {
40 $lb = wfGetLBFactory()->getExternalLB( $cluster );
41
42 return $lb->getConnection( DB_REPLICA );
43 }
44
45 public function execute() {
46 $dbr = $this->getDB( DB_REPLICA );
47 if ( !$dbr->tableExists( 'blob_orphans' ) ) {
48 $this->error( "blob_orphans doesn't seem to exist, need to run trackBlobs.php first", true );
49 }
50 $res = $dbr->select( 'blob_orphans', '*', false, __METHOD__ );
51
52 $num = 0;
53 $totalSize = 0;
54 $hashes = [];
55 $maxSize = 0;
56
57 foreach ( $res as $boRow ) {
58 $extDB = $this->getDB( $boRow->bo_cluster );
59 $blobRow = $extDB->selectRow(
60 'blobs',
61 '*',
62 [ 'blob_id' => $boRow->bo_blob_id ],
63 __METHOD__
64 );
65
66 $num++;
67 $size = strlen( $blobRow->blob_text );
68 $totalSize += $size;
69 $hashes[sha1( $blobRow->blob_text )] = true;
70 $maxSize = max( $size, $maxSize );
71 }
72 unset( $res );
73
74 $this->output( "Number of orphans: $num\n" );
75 if ( $num > 0 ) {
76 $this->output( "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" .
77 "Max size: $maxSize\n" .
78 "Number of unique texts: " . count( $hashes ) . "\n" );
79 }
80 }
81}
82
83$maintClass = "OrphanStats";
84require_once RUN_MAINTENANCE_IF_MAIN;
wfGetLBFactory()
Get the load balancer factory object.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addDescription( $text)
Set the description text.
Maintenance script that shows some statistics on the blob_orphans table, created with trackBlobs....
& getDB( $cluster, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
__construct()
Default constructor.
execute()
Do the actual work.
if(! $regexes) $dbr
Definition cleanup.php:94
$res
Definition database.txt:21
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition hooks.txt:2581
require_once RUN_MAINTENANCE_IF_MAIN
$maintClass
const DB_REPLICA
Definition defines.php:25