Localisation updates from https://translatewiki.net.
[mediawiki.git] / maintenance / storage / storageTypeStats.php
blob0b7e7ce10743b18b4eb074d5fd693a81c8dbb59b
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Maintenance ExternalStorage
22 // @codeCoverageIgnoreStart
23 require_once __DIR__ . '/../Maintenance.php';
24 // @codeCoverageIgnoreEnd
26 class StorageTypeStats extends Maintenance {
27 public function execute() {
28 $dbr = $this->getReplicaDB();
30 $endId = $dbr->newSelectQueryBuilder()
31 ->select( 'MAX(old_id)' )
32 ->from( 'text' )
33 ->caller( __METHOD__ )->fetchField();
34 if ( !$endId ) {
35 $this->fatalError( 'No text rows!' );
38 $binSize = intval( 10 ** ( floor( log10( $endId ) ) - 3 ) );
39 if ( $binSize < 100 ) {
40 $binSize = 100;
42 echo "Using bin size of $binSize\n";
44 $stats = [];
46 $classSql = <<<SQL
47 IF(old_flags LIKE '%external%',
48 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$',
49 'CGZ pointer',
50 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$',
51 'DHB pointer',
52 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+$',
53 'simple pointer',
54 'UNKNOWN pointer'
58 IF(old_flags LIKE '%object%',
59 TRIM('"' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text, ':', 3), ':', -1)),
60 '[none]'
63 SQL;
65 for ( $rangeStart = 0; $rangeStart < $endId; $rangeStart += $binSize ) {
66 if ( $rangeStart / $binSize % 10 == 0 ) {
67 echo "$rangeStart\r";
69 $res = $dbr->newSelectQueryBuilder()
70 ->select( [ 'old_flags', 'class' => $classSql, 'count' => 'COUNT(*)' ] )
71 ->from( 'text' )
72 ->where( $dbr->expr( 'old_id', '>=', intval( $rangeStart ) ) )
73 ->andWhere( $dbr->expr( 'old_id', '<', intval( $rangeStart + $binSize ) ) )
74 ->groupBy( [ 'old_flags', 'class' ] )
75 ->caller( __METHOD__ )->fetchResultSet();
77 foreach ( $res as $row ) {
78 $flags = $row->old_flags;
79 if ( $flags === '' ) {
80 $flags = '[none]';
82 $class = $row->class;
83 $count = $row->count;
84 // @phan-suppress-next-line PhanImpossibleConditionInLoop,PhanPossiblyUndeclaredVariable False positive
85 if ( !isset( $stats[$flags][$class] ) ) {
86 $stats[$flags][$class] = [
87 'count' => 0,
88 'first' => $rangeStart,
89 'last' => 0
92 $entry =& $stats[$flags][$class];
93 $entry['count'] += $count;
94 $entry['last'] = max( $entry['last'], $rangeStart + $binSize );
95 unset( $entry );
98 echo "\n\n";
100 $format = "%-29s %-39s %-19s %-29s\n";
101 printf( $format, "Flags", "Class", "Count", "old_id range" );
102 echo str_repeat( '-', 120 ) . "\n";
103 foreach ( $stats as $flags => $flagStats ) {
104 foreach ( $flagStats as $class => $entry ) {
105 printf( $format, $flags, $class, $entry['count'],
106 sprintf( "%-13d - %-13d", $entry['first'], $entry['last'] ) );
112 // @codeCoverageIgnoreStart
113 $maintClass = StorageTypeStats::class;
114 require_once RUN_MAINTENANCE_IF_MAIN;
115 // @codeCoverageIgnoreEnd