mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
[4] Add revision local cache holder object
Change-Id: I85f68b3ca269c711a8a177e013bd8eba38833444
This commit is contained in:
parent
49350a5b52
commit
55fb42b681
1
Echo.php
1
Echo.php
|
@ -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
68
includes/cache/RevisionLocalCache.php
vendored
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
3
includes/cache/TitleLocalCache.php
vendored
3
includes/cache/TitleLocalCache.php
vendored
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Cache class that maps article id to Title object
|
||||
*/
|
||||
class EchoTitleLocalCache extends EchoLocalCache {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue