Merge "Use MainWANObjectCache to improve performance"
This commit is contained in:
commit
228317e7c6
2 changed files with 48 additions and 15 deletions
|
@ -3,7 +3,7 @@
|
||||||
"author": "Tim Laqua",
|
"author": "Tim Laqua",
|
||||||
"url": "https://www.mediawiki.org/wiki/Extension:Contribution_Scores",
|
"url": "https://www.mediawiki.org/wiki/Extension:Contribution_Scores",
|
||||||
"descriptionmsg": "contributionscores-desc",
|
"descriptionmsg": "contributionscores-desc",
|
||||||
"version": "1.26.0",
|
"version": "1.26.1",
|
||||||
"type": "specialpage",
|
"type": "specialpage",
|
||||||
"requires": {
|
"requires": {
|
||||||
"MediaWiki": ">= 1.34.0"
|
"MediaWiki": ">= 1.34.0"
|
||||||
|
@ -54,6 +54,10 @@
|
||||||
"ContribScoreUseRoughEditCount": {
|
"ContribScoreUseRoughEditCount": {
|
||||||
"value": false,
|
"value": false,
|
||||||
"description": "Set to true to use the rough number of edits in user table, for performance issue."
|
"description": "Set to true to use the rough number of edits in user table, for performance issue."
|
||||||
|
},
|
||||||
|
"ContribScoreCacheTTL": {
|
||||||
|
"value": 30,
|
||||||
|
"description": "Cache the contribution scores data, in minutes."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"manifest_version": 2
|
"manifest_version": 2
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
* \brief Contains code for the ContributionScores Class (extends SpecialPage).
|
* \brief Contains code for the ContributionScores Class (extends SpecialPage).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
|
|
||||||
/// Special page class for the Contribution Scores extension
|
/// Special page class for the Contribution Scores extension
|
||||||
/**
|
/**
|
||||||
* Special page that generates a list of wiki contributors based
|
* Special page that generates a list of wiki contributors based
|
||||||
|
@ -80,22 +82,16 @@ class ContributionScores extends IncludableSpecialPage {
|
||||||
return $parser->insertStripItem( $output, $parser->mStripState );
|
return $parser->insertStripItem( $output, $parser->mStripState );
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates a "Contribution Scores" table for a given LIMIT and date range
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function generates Contribution Scores tables in HTML format (not wikiText)
|
* Function fetch Contribution Scores data from database
|
||||||
*
|
*
|
||||||
* @param int $days Days in the past to run report for
|
* @param int $days Days in the past to run report for
|
||||||
* @param int $limit Maximum number of users to return (default 50)
|
* @param int $limit Maximum number of users to return (default 50)
|
||||||
* @param string|null $title The title of the table
|
* @return array Data including the requested Contribution Scores.
|
||||||
* @param array $options array of options (default none; nosort/notools)
|
|
||||||
* @return string Html Table representing the requested Contribution Scores.
|
|
||||||
*/
|
*/
|
||||||
function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) {
|
public static function getContributionScoreData( $days, $limit ) {
|
||||||
global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoreIgnoreUsernames,
|
global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoreIgnoreUsernames,
|
||||||
$wgContribScoresUseRealName, $wgContribScoreUseRoughEditCount;
|
$wgContribScoreUseRoughEditCount;
|
||||||
|
|
||||||
$opts = explode( ',', strtolower( $options ) );
|
|
||||||
|
|
||||||
$dbr = wfGetDB( DB_REPLICA );
|
$dbr = wfGetDB( DB_REPLICA );
|
||||||
|
|
||||||
|
@ -202,6 +198,25 @@ class ContributionScores extends IncludableSpecialPage {
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
$ret = iterator_to_array( $res );
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generates a "Contribution Scores" table for a given LIMIT and date range
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function generates Contribution Scores tables in HTML format (not wikiText)
|
||||||
|
*
|
||||||
|
* @param int $days Days in the past to run report for
|
||||||
|
* @param int $limit Maximum number of users to return (default 50)
|
||||||
|
* @param string|null $title The title of the table
|
||||||
|
* @param array $options array of options (default none; nosort/notools)
|
||||||
|
* @return string Html Table representing the requested Contribution Scores.
|
||||||
|
*/
|
||||||
|
function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) {
|
||||||
|
global $wgContribScoresUseRealName, $wgContribScoreCacheTTL;
|
||||||
|
|
||||||
|
$opts = explode( ',', strtolower( $options ) );
|
||||||
|
|
||||||
$sortable = in_array( 'nosort', $opts ) ? '' : ' sortable';
|
$sortable = in_array( 'nosort', $opts ) ? '' : ' sortable';
|
||||||
|
|
||||||
|
@ -213,11 +228,26 @@ class ContributionScores extends IncludableSpecialPage {
|
||||||
Html::element( 'th', [], $this->msg( 'contributionscores-changes' )->text() ) .
|
Html::element( 'th', [], $this->msg( 'contributionscores-changes' )->text() ) .
|
||||||
Html::element( 'th', [], $this->msg( 'contributionscores-username' )->text() );
|
Html::element( 'th', [], $this->msg( 'contributionscores-username' )->text() );
|
||||||
|
|
||||||
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
||||||
|
$data = $cache->getWithSetCallback(
|
||||||
|
$cache->makeKey( 'contributionscores', 'data-' . (string)$days ),
|
||||||
|
$wgContribScoreCacheTTL * 60,
|
||||||
|
function () use ( $days ) {
|
||||||
|
// Use max limit, as limit doesn't matter with performance.
|
||||||
|
// Avoid purge multiple times since limit on transclusion can be vary.
|
||||||
|
return self::getContributionScoreData( $days, self::CONTRIBUTIONSCORES_MAXINCLUDELIMIT );
|
||||||
|
} );
|
||||||
|
|
||||||
|
$lang = $this->getLanguage();
|
||||||
|
|
||||||
$altrow = '';
|
$altrow = '';
|
||||||
$user_rank = 1;
|
$user_rank = 1;
|
||||||
|
|
||||||
$lang = $this->getLanguage();
|
foreach ( $data as $row ) {
|
||||||
foreach ( $res as $row ) {
|
if ( $user_rank > $limit ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Use real name if option used and real name present.
|
// Use real name if option used and real name present.
|
||||||
if ( $wgContribScoresUseRealName && $row->user_real_name !== '' ) {
|
if ( $wgContribScoresUseRealName && $row->user_real_name !== '' ) {
|
||||||
$userLink = Linker::userLink(
|
$userLink = Linker::userLink(
|
||||||
|
@ -263,8 +293,7 @@ class ContributionScores extends IncludableSpecialPage {
|
||||||
$output .= Html::closeElement( 'tr' );
|
$output .= Html::closeElement( 'tr' );
|
||||||
$output .= Html::closeElement( 'table' );
|
$output .= Html::closeElement( 'table' );
|
||||||
|
|
||||||
$dbr->freeResult( $res );
|
// Transcluded on a normal wiki page.
|
||||||
|
|
||||||
if ( !empty( $title ) ) {
|
if ( !empty( $title ) ) {
|
||||||
$output = Html::rawElement( 'table',
|
$output = Html::rawElement( 'table',
|
||||||
[
|
[
|
||||||
|
|
Loading…
Add table
Reference in a new issue