mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 01:30:15 +00:00
1270da19e8
Core titleCache doesn't do what I expect it to do, issuing Title::newFromId( 1 ) mulitple times would issue multiple idential queries to the database. It doesn't return what's already in the cache. The goal of this patch is to batch load titles via newFromIDs, and save the number of mysql queries Change-Id: I8fe767ac2669e67bdf7d17eecccfc0dcb6b5fc7d
47 lines
891 B
PHP
47 lines
891 B
PHP
<?php
|
|
|
|
class EchoTitleLocalCache extends EchoLocalCache {
|
|
|
|
/**
|
|
* @var EchoTitleLocalCache
|
|
*/
|
|
private static $instance;
|
|
|
|
/**
|
|
* The current wiki id
|
|
* @var string|null
|
|
*/
|
|
private static $wiki;
|
|
|
|
/**
|
|
* Create a TitleLocalCache object
|
|
* @return TitleLocalCache
|
|
*/
|
|
public static function create() {
|
|
// A job queue may run against multiple wikis,
|
|
// initialize a new one for the current wiki
|
|
if ( wfWikiId() != self::$wiki ) {
|
|
self::$instance = null;
|
|
self::$wiki = wfWikiId();
|
|
}
|
|
if ( !self::$instance ) {
|
|
self::$instance = new EchoTitleLocalCache();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
protected function resolve() {
|
|
if ( $this->lookups ) {
|
|
$titles = Title::newFromIDs( $this->lookups );
|
|
foreach ( $titles as $title ) {
|
|
$this->targets->set( $title->getArticleId(), $title );
|
|
}
|
|
$this->lookups = array();
|
|
}
|
|
}
|
|
|
|
}
|