mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-24 00:06:25 +00:00
AllInfoboxes cache improvements
This commit is contained in:
parent
3e560943f4
commit
f06a0afd6d
|
@ -12,39 +12,15 @@ class ApiQueryAllinfoboxes extends ApiQueryBase {
|
|||
$cachekey = $cache->makeKey( self::MCACHE_KEY );
|
||||
|
||||
$data = $cache->getWithSetCallback( $cachekey, self::CACHE_TTL, function () use ( $db ) {
|
||||
global $wgPortableInfoboxApiCanTriggerRecache;
|
||||
|
||||
$out = [];
|
||||
|
||||
if( $wgPortableInfoboxApiCanTriggerRecache ) {
|
||||
$res = $db->select(
|
||||
'querycache_info',
|
||||
[ 'timestamp' => 'qci_timestamp' ],
|
||||
[ 'qci_type' => AllinfoboxesQueryPage::ALL_INFOBOXES_TYPE ],
|
||||
__METHOD__
|
||||
);
|
||||
|
||||
$recache = intval( wfTimestamp( TS_UNIX, wfTimestampNow() ) ) - self::CACHE_TTL;
|
||||
$lastcache = wfTimestamp( TS_UNIX, $res->fetchObject()->timestamp );
|
||||
|
||||
if( $lastcache < $recache ) {
|
||||
(new AllinfoboxesQueryPage())->recache();
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->select(
|
||||
'querycache',
|
||||
[ 'qc_value', 'qc_title', 'qc_namespace' ],
|
||||
[ 'qc_type' => AllinfoboxesQueryPage::ALL_INFOBOXES_TYPE ],
|
||||
__METHOD__
|
||||
);
|
||||
|
||||
$res = ( new AllinfoboxesQueryPage() )->doQuery();
|
||||
while( $row = $res->fetchObject() ) {
|
||||
$out[] = [
|
||||
'pageid' => $row->qc_value,
|
||||
'title' => $row->qc_title,
|
||||
'label' => $this->createLabel( $row->qc_title ),
|
||||
'ns' => $row->qc_namespace
|
||||
'pageid' => $row->value,
|
||||
'title' => $row->title,
|
||||
'label' => $this->createLabel( $row->title ),
|
||||
'ns' => $row->namespace
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"type": "parserhook",
|
||||
"license-name": "GPL-3.0-or-later",
|
||||
"config": {
|
||||
"PortableInfoboxApiCanTriggerRecache": true
|
||||
"AllInfoboxesSubpagesBlacklist": [ "doc", "draft", "test" ],
|
||||
"AllInfoboxesMiserMode": true
|
||||
},
|
||||
"MessagesDirs": {
|
||||
"PortableInfobox": "i18n"
|
||||
|
|
|
@ -3,10 +3,15 @@
|
|||
class AllinfoboxesQueryPage extends PageQueryPage {
|
||||
|
||||
const ALL_INFOBOXES_TYPE = 'AllInfoboxes';
|
||||
private static $subpagesBlacklist = [ 'doc', 'draft', 'test' ];
|
||||
private static $subpagesBlacklist = [];
|
||||
|
||||
function __construct() {
|
||||
parent::__construct( self::ALL_INFOBOXES_TYPE );
|
||||
|
||||
$blacklist = $this->getConfig( 'AllInfoboxesSubpagesBlacklist' );
|
||||
if( is_array( $blacklist ) ) {
|
||||
self::$subpagesBlacklist = $blacklist;
|
||||
}
|
||||
}
|
||||
|
||||
function getGroupName() {
|
||||
|
@ -21,6 +26,13 @@ class AllinfoboxesQueryPage extends PageQueryPage {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function isCached() {
|
||||
return $this->isExpensive() && (
|
||||
$this->getConfig()->get( 'MiserMode' ) ||
|
||||
$this->getConfig()->get( 'AllInfoboxesMiserMode' )
|
||||
);
|
||||
}
|
||||
|
||||
public function getOrderFields() {
|
||||
return [ 'title' ];
|
||||
}
|
||||
|
@ -47,8 +59,10 @@ class AllinfoboxesQueryPage extends PageQueryPage {
|
|||
/**
|
||||
* Update the querycache table
|
||||
*
|
||||
* @see QueryPage::recache
|
||||
*
|
||||
* @param bool $limit Only for consistency
|
||||
* @param bool $ignoreErrors Only for consistency
|
||||
* @param bool $ignoreErrors Whether to ignore database errors
|
||||
*
|
||||
* @return int number of rows updated
|
||||
*/
|
||||
|
@ -64,8 +78,8 @@ class AllinfoboxesQueryPage extends PageQueryPage {
|
|||
*
|
||||
* @see QueryPage::reallyDoQuery
|
||||
*
|
||||
* @param bool $limit Only for consistency
|
||||
* @param bool $offset Only for consistency
|
||||
* @param int|bool $limit Numerical limit or false for no limit
|
||||
* @param int|bool $offset Numerical offset or false for no limit
|
||||
*
|
||||
* @return ResultWrapper
|
||||
*/
|
||||
|
@ -73,13 +87,21 @@ class AllinfoboxesQueryPage extends PageQueryPage {
|
|||
$res = parent::reallyDoQuery( false );
|
||||
$out = [];
|
||||
|
||||
while ( $row = $res->fetchObject() ) {
|
||||
if($this->filterInfoboxes( $row )) {
|
||||
$maxResults = $this->getMaxResults();
|
||||
if ( $limit == 0 ) {
|
||||
$limit = $maxResults;
|
||||
} else {
|
||||
$limit = min( $limit, $maxResults );
|
||||
}
|
||||
|
||||
while ( $limit >= 0 && $row = $res->fetchObject() ) {
|
||||
if( $this->filterInfoboxes( $row ) && $offset-- <= 0 ) {
|
||||
$out[] = $row;
|
||||
$limit--;
|
||||
}
|
||||
}
|
||||
|
||||
return new FakeResultWrapper($out);
|
||||
return new FakeResultWrapper( $out );
|
||||
}
|
||||
|
||||
public function addTitleToCache( Title $title ) {
|
||||
|
|
Loading…
Reference in a new issue