- global $wgChangeTagsSchemaMigrationStage, $wgTagStatisticsNewTable;
- if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ||
- ( $wgTagStatisticsNewTable && $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD )
- ) {
- return self::newTagUsageStatistics();
- }
-
- $fname = __METHOD__;
- $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
- return $cache->getWithSetCallback(
- $cache->makeKey( 'change-tag-statistics' ),
- WANObjectCache::TTL_MINUTE * 5,
- function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
- $dbr = wfGetDB( DB_REPLICA, 'vslow' );
-
- $setOpts += Database::getCacheSetOptions( $dbr );
-
- $res = $dbr->select(
- 'change_tag',
- [ 'ct_tag', 'hitcount' => 'count(*)' ],
- [],
- $fname,
- [ 'GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC' ]
- );
-
- $out = [];
- foreach ( $res as $row ) {
- $out[$row->ct_tag] = $row->hitcount;
- }
-
- return $out;
- },
- [
- 'checkKeys' => [ $cache->makeKey( 'change-tag-statistics' ) ],
- 'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
- 'pcTTL' => WANObjectCache::TTL_PROC_LONG
- ]
- );
- }
-
- /**
- * Same self::tagUsageStatistics() but uses change_tag_def.
- *
- * @return array Array of string => int
- */
- private static function newTagUsageStatistics() {