43 protected static function load() {
44 if ( self::$row ===
null ) {
53 $config = MediaWikiServices::getInstance()->getMainConfig();
57 wfDebug( __METHOD__ .
": reading site_stats from replica DB" );
58 $row = self::doLoadFromDB(
$dbr );
60 if ( !self::isRowSensible( $row ) && $lb->hasOrMadeRecentPrimaryChanges() ) {
62 wfDebug( __METHOD__ .
": site_stats damaged or missing on replica DB" );
63 $row = self::doLoadFromDB( $lb->getConnectionRef(
DB_PRIMARY ) );
66 if ( !self::isRowSensible( $row ) ) {
67 if ( $config->get( MainConfigNames::MiserMode ) ) {
76 wfDebug( __METHOD__ .
": initializing damaged or missing site_stats" );
80 $row = self::doLoadFromDB( $lb->getConnectionRef(
DB_PRIMARY ) );
89 public static function edits() {
92 return (
int)self::$row->ss_total_edits;
101 return (
int)self::$row->ss_good_articles;
110 return (
int)self::$row->ss_total_pages;
119 return (
int)self::$row->ss_users;
128 return (
int)self::$row->ss_active_users;
137 return (
int)self::$row->ss_images;
146 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
149 return $cache->getWithSetCallback(
150 $cache->makeKey(
'SiteStats',
'groupcounts', $group ),
152 function ( $oldValue, &$ttl, array &$setOpts ) use ( $group, $fname ) {
154 $setOpts += Database::getCacheSetOptions(
$dbr );
155 return (
int)
$dbr->newSelectQueryBuilder()
156 ->select(
'COUNT(*)' )
157 ->from(
'user_groups' )
160 'ug_group' => $group,
161 'ug_expiry IS NULL OR ug_expiry >= ' .
$dbr->addQuotes(
$dbr->timestamp() )
167 [
'pcTTL' => $cache::TTL_PROC_LONG ]
175 public static function jobs() {
176 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
178 return $cache->getWithSetCallback(
179 $cache->makeKey(
'SiteStats',
'jobscount' ),
181 static function ( $oldValue, &$ttl, array &$setOpts ) {
183 $jobs = array_sum( MediaWikiServices::getInstance()->getJobQueueGroup()->getQueueSizes() );
189 [
'pcTTL' => $cache::TTL_PROC_LONG ]
198 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
201 return $cache->getWithSetCallback(
202 $cache->makeKey(
'SiteStats',
'page-in-namespace', $ns ),
204 function ( $oldValue, &$ttl, array &$setOpts ) use ( $ns, $fname ) {
206 $setOpts += Database::getCacheSetOptions(
$dbr );
208 return (
int)
$dbr->selectField(
211 [
'page_namespace' => $ns ],
215 [
'pcTTL' => $cache::TTL_PROC_LONG ]
237 private static function doLoadFromDB(
IDatabase $db ) {
241 ->from(
'site_stats' )
242 ->caller( __METHOD__ )
244 if ( !$rows->numRows() ) {
247 $finalRow =
new stdClass();
248 foreach ( $rows as $row ) {
249 foreach ( $fields as $field ) {
250 $finalRow->$field ??= 0;
251 if ( $row->$field ) {
252 $finalRow->$field += $row->$field;
268 private static function isRowSensible( $row ) {
270 || $row->ss_total_pages < $row->ss_good_articles
271 || $row->ss_total_edits < $row->ss_total_pages
283 if ( $row->$member < 0 ) {
294 private static function getLB() {
295 return MediaWikiServices::getInstance()->getDBLoadBalancer();
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.
static doAllAndCommit( $database, array $options=[])
Do all updates and commit them.
static doPlaceholderInit()
Insert a dummy row with all zeroes if no row is present.
Static accessor class for site_stats and related things.
static jobs()
Total number of jobs in the job queue.
static unload()
Trigger a reload next time a field is accessed.
static numberingroup( $group)
Find the number of users in a given user group.