47 protected static function load() {
48 if ( self::$row ===
null ) {
61 wfDebug( __METHOD__ .
": reading site_stats from replica DB" );
62 $row = self::doLoadFromDB( $dbr );
64 if ( !self::isRowSensible( $row ) && $lb->hasOrMadeRecentPrimaryChanges() ) {
66 wfDebug( __METHOD__ .
": site_stats damaged or missing on replica DB" );
67 $row = self::doLoadFromDB( $lb->getConnection(
DB_PRIMARY ) );
70 if ( !self::isRowSensible( $row ) ) {
80 wfDebug( __METHOD__ .
": initializing damaged or missing site_stats" );
84 $row = self::doLoadFromDB( $lb->getConnection(
DB_PRIMARY ) );
93 public static function edits() {
96 return (
int)self::$row->ss_total_edits;
105 return (
int)self::$row->ss_good_articles;
114 return (
int)self::$row->ss_total_pages;
123 return (
int)self::$row->ss_users;
132 return (
int)self::$row->ss_active_users;
141 return (
int)self::$row->ss_images;
153 return $cache->getWithSetCallback(
154 $cache->makeKey(
'SiteStats',
'groupcounts', $group ),
156 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $group, $fname ) {
157 $dbr = self::getLB()->getConnection(
DB_REPLICA );
159 return (
int)$dbr->newSelectQueryBuilder()
160 ->select(
'COUNT(*)' )
161 ->from(
'user_groups' )
164 'ug_group' => $group,
165 $dbr->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $dbr->timestamp() )
171 [
'pcTTL' => $cache::TTL_PROC_LONG ]
179 public static function jobs() {
182 return $cache->getWithSetCallback(
183 $cache->makeKey(
'SiteStats',
'jobscount' ),
185 static function ( $oldValue, &$ttl, array &$setOpts ) {
193 [
'pcTTL' => $cache::TTL_PROC_LONG ]
205 return $cache->getWithSetCallback(
206 $cache->makeKey(
'SiteStats',
'page-in-namespace', $ns ),
208 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $ns, $fname ) {
209 $dbr = self::getLB()->getConnection(
DB_REPLICA );
212 return (
int)$dbr->newSelectQueryBuilder()
213 ->select(
'COUNT(*)' )
215 ->where( [
'page_namespace' => $ns ] )
216 ->caller( $fname )->fetchField();
218 [
'pcTTL' => $cache::TTL_PROC_LONG ]
244 ->from(
'site_stats' )
245 ->caller( __METHOD__ )
247 if ( !$rows->numRows() ) {
250 $finalRow =
new stdClass();
251 foreach ( $rows as $row ) {
252 foreach ( $fields as $field ) {
253 $finalRow->$field ??= 0;
254 if ( $row->$field ) {
255 $finalRow->$field += $row->$field;
271 private static function isRowSensible( $row ) {
273 || $row->ss_total_pages < $row->ss_good_articles
274 || $row->ss_total_edits < $row->ss_total_pages
286 if ( $row->$member < 0 ) {
297 private static function getLB() {
303class_alias( SiteStats::class,
'SiteStats' );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
A class containing constants representing the names of configuration variables.
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()