mediawiki-extensions-Echo/includes/cache/TitleLocalCache.php
bsitu 1270da19e8 [2] Add title local cache holder objects
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
2014-08-18 13:52:40 -07:00

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();
}
}
}