Add a feature flag to turn off the 'active users' query on GadgetUsage

Currently takes >24 hours to complete on enwiki and thus isn't run
at all. Need a better optimised query. Until that happens, we can
turn it off on enwiki.

Bug: T121484
Change-Id: Idcf2a8a1cdf5ce4c2f6a631ef980be5a48ca547b
This commit is contained in:
niharika29 2015-12-17 14:03:21 +00:00
parent 97f6b1589a
commit 75ae3558e7
4 changed files with 77 additions and 35 deletions

View file

@ -33,8 +33,18 @@ class SpecialGadgetUsage extends QueryPage {
parent::__construct( $name );
$this->limit = 1000; // Show all gadgets
$this->shownavigation = false;
$this->activeUsers = $this->getConfig()->get( 'SpecialGadgetUsageActiveUsers' );
}
/**
* Flag for holding the value of config variable SpecialGadgetUsageActiveUsers
*
* @var bool $activeUsers
*/
public $activeUsers;
public function isExpensive() {
return true;
}
@ -50,35 +60,52 @@ class SpecialGadgetUsage extends QueryPage {
*/
public function getQueryInfo() {
$dbr = wfGetDB( DB_SLAVE );
return array(
'tables' => array( 'user_properties', 'user', 'querycachetwo' ),
'fields' => array(
'title' => 'up_property',
'value' => 'SUM( up_value )',
// Need to pick fields existing in the querycache table so that the results are cachable
'namespace' => 'COUNT( qcc_title )'
),
'conds' => array(
'up_property' . $dbr->buildLike( 'gadget-', $dbr->anyString() )
),
'options' => array(
'GROUP BY' => array( 'up_property' )
),
'join_conds' => array(
'user' => array(
'LEFT JOIN', array(
'up_user = user_id'
)
if ( !$this->activeUsers ) {
return array(
'tables' => array( 'user_properties' ),
'fields' => array(
'title' => 'up_property',
'value' => 'SUM( up_value )',
'namespace' => NS_GADGET
),
'querycachetwo' => array(
'LEFT JOIN', array(
'user_name = qcc_title',
'qcc_type = "activeusers"',
'up_value = 1'
'conds' => array(
'up_property' . $dbr->buildLike( 'gadget-', $dbr->anyString() )
),
'options' => array(
'GROUP BY' => array( 'up_property' )
)
);
} else {
return array(
'tables' => array( 'user_properties', 'user', 'querycachetwo' ),
'fields' => array(
'title' => 'up_property',
'value' => 'SUM( up_value )',
// Need to pick fields existing in the querycache table so that the results are cachable
'namespace' => 'COUNT( qcc_title )'
),
'conds' => array(
'up_property' . $dbr->buildLike( 'gadget-', $dbr->anyString() )
),
'options' => array(
'GROUP BY' => array( 'up_property' )
),
'join_conds' => array(
'user' => array(
'LEFT JOIN', array(
'up_user = user_id'
)
),
'querycachetwo' => array(
'LEFT JOIN', array(
'user_name = qcc_title',
'qcc_type = "activeusers"',
'up_value = 1'
)
)
)
)
);
);
}
}
public function getOrderFields() {
@ -92,8 +119,10 @@ class SpecialGadgetUsage extends QueryPage {
protected function outputTableStart() {
$html = Html::openElement( 'table', array( 'class' => array( 'sortable', 'wikitable' ) ) );
$html .= Html::openElement( 'tr', array() );
$headers = array( 'gadgetusage-gadget', 'gadgetusage-usercount', 'gadgetusage-activeusers' );
$headers = array( 'gadgetusage-gadget', 'gadgetusage-usercount' );
if ( $this->activeUsers ) {
$headers[] = 'gadgetusage-activeusers';
}
foreach( $headers as $h ) {
$html .= Html::element( 'th', array(), $this->msg( $h )->text() );
}
@ -109,12 +138,14 @@ class SpecialGadgetUsage extends QueryPage {
public function formatResult( $skin, $result ) {
$gadgetTitle = substr( $result->title, 7 );
$gadgetUserCount = $this->getLanguage()->formatNum( $result->value );
$activeUsers = $this->getLanguage()->formatNum( $result->namespace );
if ( $gadgetTitle ) {
$html = Html::openElement( 'tr', array() );
$html .= Html::element( 'td', array(), $gadgetTitle );
$html .= Html::element( 'td', array(), $gadgetUserCount );
$html .= Html::element( 'td', array(), $activeUsers );
if ( $this->activeUsers == true ) {
$activeUserCount = $this->getLanguage()->formatNum( $result->namespace );
$html .= Html::element( 'td', array(), $activeUserCount );
}
$html .= Html::closeElement( 'tr' );
return $html;
}
@ -154,9 +185,15 @@ class SpecialGadgetUsage extends QueryPage {
$gadgetRepo = GadgetRepo::singleton();
$gadgetIds = $gadgetRepo->getGadgetIds();
$defaultGadgets = $this->getDefaultGadgets( $gadgetRepo, $gadgetIds );
$out->addHtml(
$this->msg( 'gadgetusage-intro', $this->getConfig()->get( 'ActiveUserDays' ) )->parseAsBlock()
);
if ( $this->activeUsers ) {
$out->addHtml(
$this->msg( 'gadgetusage-intro', $this->getConfig()->get( 'ActiveUserDays' ) )->parseAsBlock()
);
} else {
$out->addHtml(
$this->msg( 'gadgetusage-intro-noactive' )->parseAsBlock()
);
}
if ( $num > 0 ) {
$this->outputTableStart();
// Append default gadgets to the table with 'default' in the total and active user fields
@ -164,7 +201,9 @@ class SpecialGadgetUsage extends QueryPage {
$html = Html::openElement( 'tr', array() );
$html .= Html::element( 'td', array(), $default );
$html .= Html::element( 'td', array(), $this->msg( 'gadgetusage-default' ) );
$html .= Html::element( 'td', array(), $this->msg( 'gadgetusage-default' ) );
if ( $this->activeUsers ) {
$html .= Html::element( 'td', array(), $this->msg( 'gadgetusage-default' ) );
}
$html .= Html::closeElement( 'tr' );
$out->addHTML( $html );
}

View file

@ -111,7 +111,8 @@
]
},
"config": {
"GadgetsRepoClass": "MediaWikiGadgetsDefinitionRepo"
"GadgetsRepoClass": "MediaWikiGadgetsDefinitionRepo",
"SpecialGadgetUsageActiveUsers": true
},
"manifest_version": 1
}

View file

@ -13,6 +13,7 @@
"gadgetusage-usercount": "Number of users",
"gadgetusage-noresults": "No gadgets found.",
"gadgetusage-intro": "This table indicates the number of users who have enabled each gadget on this wiki. An active user is counted as someone who has made an edit in the last {{PLURAL:$1|day|$1 days}}. This list excludes stats for gadgets enabled for everyone by default and may include gadgets that are no longer available.",
"gadgetusage-intro-noactive": "This table indicates the number of users who have enabled each gadget on this wiki. This list excludes stats for gadgets enabled for everyone by default and may include gadgets that are no longer available.",
"gadgetusage-activeusers": "Active users",
"gadgetusage-default": "Default",
"gadgets-definition": "",

View file

@ -25,6 +25,7 @@
"gadgetusage-usercount": "Table column header on [[Special:GadgetUsage]]",
"gadgetusage-noresults": "Message shown to user when no gadgets found installed on the wiki. Used on [[Special:GadgetUsage]]",
"gadgetusage-intro": "Intro text on [[Special:GadgetUsage]] Parameter:\n* $1 - the number of days to consider for defining a user as active",
"gadgetusage-intro-noactive": "Intro text on [[Special:GadgetUsage]]",
"gadgetusage-activeusers": "Table column header for active users using a gadget",
"gadgetusage-default": "Message to indicate the gadget is default and actual stats are not available",
"gadgets-definition": "{{notranslate}}",