MediaWiki REL1_31
storageTypeStats.php
Go to the documentation of this file.
1<?php
22require_once __DIR__ . '/../Maintenance.php';
23
25 function execute() {
26 $dbr = $this->getDB( DB_REPLICA );
27
28 $endId = $dbr->selectField( 'text', 'MAX(old_id)', '', __METHOD__ );
29 if ( !$endId ) {
30 echo "No text rows!\n";
31 exit( 1 );
32 }
33
34 $binSize = intval( pow( 10, floor( log10( $endId ) ) - 3 ) );
35 if ( $binSize < 100 ) {
36 $binSize = 100;
37 }
38 echo "Using bin size of $binSize\n";
39
40 $stats = [];
41
42 $classSql = <<<SQL
43 IF(old_flags LIKE '%external%',
44 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$',
45 'CGZ pointer',
46 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$',
47 'DHB pointer',
48 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+$',
49 'simple pointer',
50 'UNKNOWN pointer'
51 )
52 )
53 ),
54 IF(old_flags LIKE '%object%',
55 TRIM('"' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text, ':', 3), ':', -1)),
56 '[none]'
57 )
58 )
59SQL;
60
61 for ( $rangeStart = 0; $rangeStart < $endId; $rangeStart += $binSize ) {
62 if ( $rangeStart / $binSize % 10 == 0 ) {
63 echo "$rangeStart\r";
64 }
65 $res = $dbr->select(
66 'text',
67 [
68 'old_flags',
69 "$classSql AS class",
70 'COUNT(*) as count',
71 ],
72 [
73 'old_id >= ' . intval( $rangeStart ),
74 'old_id < ' . intval( $rangeStart + $binSize )
75 ],
76 __METHOD__,
77 [ 'GROUP BY' => 'old_flags, class' ]
78 );
79
80 foreach ( $res as $row ) {
81 $flags = $row->old_flags;
82 if ( $flags === '' ) {
83 $flags = '[none]';
84 }
85 $class = $row->class;
86 $count = $row->count;
87 if ( !isset( $stats[$flags][$class] ) ) {
88 $stats[$flags][$class] = [
89 'count' => 0,
90 'first' => $rangeStart,
91 'last' => 0
92 ];
93 }
94 $entry =& $stats[$flags][$class];
95 $entry['count'] += $count;
96 $entry['last'] = max( $entry['last'], $rangeStart + $binSize );
97 unset( $entry );
98 }
99 }
100 echo "\n\n";
101
102 $format = "%-29s %-39s %-19s %-29s\n";
103 printf( $format, "Flags", "Class", "Count", "old_id range" );
104 echo str_repeat( '-', 120 ) . "\n";
105 foreach ( $stats as $flags => $flagStats ) {
106 foreach ( $flagStats as $class => $entry ) {
107 printf( $format, $flags, $class, $entry['count'],
108 sprintf( "%-13d - %-13d", $entry['first'], $entry['last'] ) );
109 }
110 }
111 }
112}
113
114$maintClass = StorageTypeStats::class;
115require_once RUN_MAINTENANCE_IF_MAIN;
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR ARISING FROM
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
execute()
Do the actual work.
$res
Definition database.txt:21
require_once RUN_MAINTENANCE_IF_MAIN
const DB_REPLICA
Definition defines.php:25