MediaWiki  1.29.1
storageTypeStats.php
Go to the documentation of this file.
1 <?php
22 require_once __DIR__ . '/../Maintenance.php';
23 
25  function execute() {
26  $dbr = $this->getDB( DB_REPLICA );
27 
28  $endId = $dbr->selectField( 'text', 'MAX(old_id)', false, __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  )
59 SQL;
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';
115 require_once RUN_MAINTENANCE_IF_MAIN;
StorageTypeStats\execute
execute()
Do the actual work.
Definition: storageTypeStats.php:25
FROM
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
Definition: MIT-LICENSE.txt:10
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$res
$res
Definition: database.txt:21
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
$maintClass
$maintClass
Definition: storageTypeStats.php:97
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
StorageTypeStats
Definition: storageTypeStats.php:24
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1251
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2749