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
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)' )
33 ->caller( __METHOD__
)->fetchField();
35 $this->fatalError( 'No text rows!' );
38 $binSize = intval( 10 ** ( floor( log10( $endId ) ) - 3 ) );
39 if ( $binSize < 100 ) {
42 echo "Using bin size of $binSize\n";
47 IF(old_flags LIKE '%external%',
48 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$',
50 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$',
52 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+$',
58 IF(old_flags LIKE '%object%',
59 TRIM('"' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text, ':', 3), ':', -1)),
65 for ( $rangeStart = 0; $rangeStart < $endId; $rangeStart +
= $binSize ) {
66 if ( $rangeStart / $binSize %
10 == 0 ) {
69 $res = $dbr->newSelectQueryBuilder()
70 ->select( [ 'old_flags', 'class' => $classSql, 'count' => 'COUNT(*)' ] )
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 === '' ) {
84 // @phan-suppress-next-line PhanImpossibleConditionInLoop,PhanPossiblyUndeclaredVariable False positive
85 if ( !isset( $stats[$flags][$class] ) ) {
86 $stats[$flags][$class] = [
88 'first' => $rangeStart,
92 $entry =& $stats[$flags][$class];
93 $entry['count'] +
= $count;
94 $entry['last'] = max( $entry['last'], $rangeStart +
$binSize );
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