33 protected static function load() {
34 if ( self::$row ===
null ) {
47 wfDebug( __METHOD__ .
": reading site_stats from replica DB" );
48 $row = self::doLoadFromDB( $dbr );
50 if ( !self::isRowSensible( $row ) && $lb->hasOrMadeRecentPrimaryChanges() ) {
52 wfDebug( __METHOD__ .
": site_stats damaged or missing on replica DB" );
53 $row = self::doLoadFromDB( $lb->getConnection(
DB_PRIMARY ) );
56 if ( !self::isRowSensible( $row ) ) {
66 wfDebug( __METHOD__ .
": initializing damaged or missing site_stats" );
70 $row = self::doLoadFromDB( $lb->getConnection(
DB_PRIMARY ) );
79 public static function edits() {
82 return (
int)self::$row->ss_total_edits;
91 return (
int)self::$row->ss_good_articles;
97 public static function pages() {
100 return (
int)self::$row->ss_total_pages;
109 return (
int)self::$row->ss_users;
118 return (
int)self::$row->ss_active_users;
127 return (
int)self::$row->ss_images;
139 return $cache->getWithSetCallback(
140 $cache->makeKey(
'SiteStats',
'groupcounts', $group ),
142 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $group, $fname ) {
143 $dbr = self::getLB()->getConnection(
DB_REPLICA );
145 return (
int)$dbr->newSelectQueryBuilder()
146 ->select(
'COUNT(*)' )
147 ->from(
'user_groups' )
150 'ug_group' => $group,
151 $dbr->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $dbr->timestamp() )
157 [
'pcTTL' => $cache::TTL_PROC_LONG ]
165 public static function jobs() {
168 return $cache->getWithSetCallback(
169 $cache->makeKey(
'SiteStats',
'jobscount' ),
171 static function ( $oldValue, &$ttl, array &$setOpts ) {
179 [
'pcTTL' => $cache::TTL_PROC_LONG ]
191 return $cache->getWithSetCallback(
192 $cache->makeKey(
'SiteStats',
'page-in-namespace', $ns ),
194 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $ns, $fname ) {
195 $dbr = self::getLB()->getConnection(
DB_REPLICA );
198 return (
int)$dbr->newSelectQueryBuilder()
199 ->select(
'COUNT(*)' )
201 ->where( [
'page_namespace' => $ns ] )
202 ->caller( $fname )->fetchField();
204 [
'pcTTL' => $cache::TTL_PROC_LONG ]
230 ->from(
'site_stats' )
231 ->caller( __METHOD__ )
233 if ( !$rows->numRows() ) {
236 $finalRow =
new stdClass();
237 foreach ( $rows as $row ) {
238 foreach ( $fields as $field ) {
239 $finalRow->$field ??= 0;
240 if ( $row->$field ) {
241 $finalRow->$field += $row->$field;
257 private static function isRowSensible( $row ) {
259 || $row->ss_total_pages < $row->ss_good_articles
260 || $row->ss_total_edits < $row->ss_total_pages
272 if ( $row->$member < 0 ) {
283 private static function getLB() {
289class_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()