[4] Add revision local cache holder object

Change-Id: I85f68b3ca269c711a8a177e013bd8eba38833444
This commit is contained in:
bsitu 2014-08-16 00:00:08 -07:00
parent 49350a5b52
commit 55fb42b681
4 changed files with 81 additions and 0 deletions

View file

@ -70,6 +70,7 @@ $wgAutoloadClasses['EchoUserNotificationGateway'] = $dir . 'includes/gateway/Use
// Local caches
$wgAutoloadClasses['EchoLocalCache'] = $dir . 'includes/cache/LocalCache.php';
$wgAutoloadClasses['EchoTitleLocalCache'] = $dir . 'includes/cache/TitleLocalCache.php';
$wgAutoloadClasses['EchoRevisionLocalCache'] = $dir . 'includes/cache/RevisionLocalCache.php';
// Output formatters
$wgAutoloadClasses['EchoDataOutputFormatter'] = $dir . 'includes/DataOutputFormatter.php';

68
includes/cache/RevisionLocalCache.php vendored Normal file
View file

@ -0,0 +1,68 @@
<?php
/**
* Cache class that maps revision id to Revision object
*/
class EchoRevisionLocalCache extends EchoLocalCache {
/**
* @var EchoRevisionLocalCache
*/
private static $instance;
/**
* The current wiki id
* @var string|null
*/
private static $wiki;
/**
* Create a EchoRevisionLocalCache object
* @return EchoRevisionLocalCache
*/
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 EchoRevisionLocalCache();
}
return self::$instance;
}
/**
* {@inheritDoc}
*/
protected function resolve() {
if ( $this->lookups ) {
// @Todo Add newFromIds() to Revision
$dbr = wfGetDB( DB_SLAVE );
$fields = array_merge(
Revision::selectFields(),
Revision::selectPageFields(),
Revision::selectUserFields()
);
$res = $dbr->select(
array( 'revision', 'page', 'user' ),
$fields,
array( 'rev_id' => $this->lookups ),
__METHOD__,
array(),
array(
'page' => Revision::pageJoinCond(),
'user' => Revision::userJoinCond()
)
);
if ( $res ) {
foreach ( $res as $row ) {
$this->targets->set( $row->rev_id, new Revision( $row ) );
}
$this->lookups = array();
}
}
}
}

View file

@ -1,5 +1,8 @@
<?php
/**
* Cache class that maps article id to Title object
*/
class EchoTitleLocalCache extends EchoLocalCache {
/**

View file

@ -245,6 +245,10 @@ class EchoEvent extends EchoAbstractEntity{
$titleCache = EchoTitleLocalCache::create();
$titleCache->add( $row->event_page_id );
}
if ( isset( $this->extra['revid'] ) && $this->extra['revid'] ) {
$revisionCache = EchoRevisionLocalCache::create();
$revisionCache->add( $this->extra['revid'] );
}
}
/**
@ -428,6 +432,11 @@ class EchoEvent extends EchoAbstractEntity{
if ( $this->revision ) {
return $this->revision;
} elseif ( isset( $this->extra['revid'] ) ) {
$revisionCache = EchoRevisionLocalCache::create();
$revision = $revisionCache->get( $this->extra['revid'] );
if ( $revision ) {
return $this->revision = $revision;
}
return $this->revision = Revision::newFromId( $this->extra['revid'] );
}
return null;