mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-27 17:20:40 +00:00
Namespace Cache
Change-Id: I8ead3ee485528f08f71c21cf401880bf369dbeac
This commit is contained in:
parent
548e8f1628
commit
3609edf153
|
@ -1096,7 +1096,6 @@
|
|||
"EchoFilteredSequentialIterator": "includes/iterator/FilteredSequentialIterator.php",
|
||||
"EchoForeignNotifications": "includes/ForeignNotifications.php",
|
||||
"EchoForeignWikiRequest": "includes/ForeignWikiRequest.php",
|
||||
"EchoLocalCache": "includes/cache/LocalCache.php",
|
||||
"EchoMentionPresentationModel": "includes/Formatters/EchoMentionPresentationModel.php",
|
||||
"MediaWiki\\Extension\\Notifications\\Formatters\\EchoMentionPresentationModel": "includes/Formatters/EchoMentionPresentationModel.php",
|
||||
"EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php",
|
||||
|
@ -1109,14 +1108,12 @@
|
|||
"EchoOnWikiList": "includes/EchoOnWikiList.php",
|
||||
"EchoPresentationModelSection": "includes/Formatters/EchoPresentationModelSection.php",
|
||||
"MediaWiki\\Extension\\Notifications\\Formatters\\EchoPresentationModelSection": "includes/Formatters/EchoPresentationModelSection.php",
|
||||
"EchoRevisionLocalCache": "includes/cache/RevisionLocalCache.php",
|
||||
"EchoSeenTime": "includes/SeenTime.php",
|
||||
"EchoServices": "includes/EchoServices.php",
|
||||
"EchoSummaryParser": "includes/EchoSummaryParser.php",
|
||||
"EchoSuppressionRowUpdateGenerator": "includes/schemaUpdate.php",
|
||||
"EchoTargetPage": "includes/model/TargetPage.php",
|
||||
"EchoTargetPageMapper": "includes/mapper/TargetPageMapper.php",
|
||||
"EchoTitleLocalCache": "includes/cache/TitleLocalCache.php",
|
||||
"EchoUnreadWikis": "includes/UnreadWikis.php",
|
||||
"EchoUserLocator": "includes/UserLocator.php",
|
||||
"GenerateSampleNotifications": "maintenance/generateSampleNotifications.php",
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Notifications\Cache;
|
||||
|
||||
use Iterator;
|
||||
use MapCacheLRU;
|
||||
|
||||
/**
|
||||
* Base Local cache object, which borrows the concept from Flow user listener
|
||||
*/
|
||||
abstract class EchoLocalCache {
|
||||
abstract class LocalCache {
|
||||
|
||||
/**
|
||||
* Max number of objects to hold in $targets. In theory, 1000
|
||||
* is very hard to reach in a normal web request. We need to
|
||||
* put cap so it doesn't reach memory limit when running email
|
||||
* put cap, so it doesn't reach memory limit when running email
|
||||
* digest against large amount of notifications
|
||||
*/
|
||||
private const TARGET_MAX_NUM = 1000;
|
||||
|
@ -34,7 +39,7 @@ abstract class EchoLocalCache {
|
|||
abstract protected function resolve( array $lookups );
|
||||
|
||||
/**
|
||||
* Use a factory method, such as EchoTitleLocalCache::create().
|
||||
* Use a factory method, such as TitleLocalCache::create().
|
||||
*
|
||||
* @private
|
||||
*/
|
|
@ -1,23 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Notifications\Cache;
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Cache class that maps revision id to RevisionStore object
|
||||
*/
|
||||
class EchoRevisionLocalCache extends EchoLocalCache {
|
||||
class RevisionLocalCache extends LocalCache {
|
||||
|
||||
/**
|
||||
* @var EchoRevisionLocalCache
|
||||
* @var RevisionLocalCache
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @return EchoRevisionLocalCache
|
||||
* @return RevisionLocalCache
|
||||
*/
|
||||
public static function create() {
|
||||
if ( !self::$instance ) {
|
||||
self::$instance = new EchoRevisionLocalCache();
|
||||
self::$instance = new RevisionLocalCache();
|
||||
}
|
||||
|
||||
return self::$instance;
|
|
@ -1,24 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Notifications\Cache;
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\PageRecord;
|
||||
|
||||
/**
|
||||
* Cache class that maps article id to Title object
|
||||
*/
|
||||
class EchoTitleLocalCache extends EchoLocalCache {
|
||||
class TitleLocalCache extends LocalCache {
|
||||
|
||||
/**
|
||||
* @var EchoTitleLocalCache
|
||||
* @var TitleLocalCache
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @return EchoTitleLocalCache
|
||||
* @return TitleLocalCache
|
||||
*/
|
||||
public static function create() {
|
||||
if ( !self::$instance ) {
|
||||
self::$instance = new EchoTitleLocalCache();
|
||||
self::$instance = new TitleLocalCache();
|
||||
}
|
||||
|
||||
return self::$instance;
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Cache\RevisionLocalCache;
|
||||
use MediaWiki\Extension\Notifications\Cache\TitleLocalCache;
|
||||
use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
@ -341,11 +343,11 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
);
|
||||
}
|
||||
if ( $row->event_page_id ) {
|
||||
$titleCache = EchoTitleLocalCache::create();
|
||||
$titleCache = TitleLocalCache::create();
|
||||
$titleCache->add( (int)$row->event_page_id );
|
||||
}
|
||||
if ( isset( $this->extra['revid'] ) && $this->extra['revid'] ) {
|
||||
$revisionCache = EchoRevisionLocalCache::create();
|
||||
$revisionCache = RevisionLocalCache::create();
|
||||
$revisionCache->add( $this->extra['revid'] );
|
||||
}
|
||||
|
||||
|
@ -543,7 +545,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
return $this->title;
|
||||
}
|
||||
if ( $this->pageId ) {
|
||||
$titleCache = EchoTitleLocalCache::create();
|
||||
$titleCache = TitleLocalCache::create();
|
||||
$title = $titleCache->get( $this->pageId );
|
||||
if ( $title ) {
|
||||
$this->title = $title;
|
||||
|
@ -573,7 +575,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
}
|
||||
|
||||
if ( isset( $this->extra['revid'] ) ) {
|
||||
$revisionCache = EchoRevisionLocalCache::create();
|
||||
$revisionCache = RevisionLocalCache::create();
|
||||
$revision = $revisionCache->get( $this->extra['revid'] );
|
||||
if ( $revision ) {
|
||||
$this->revision = $revision;
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Cache\TitleLocalCache;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
/**
|
||||
* @covers \EchoTitleLocalCache
|
||||
* @covers MediaWiki\Extension\Notifications\Cache\TitleLocalCache
|
||||
* @group Database
|
||||
*/
|
||||
class EchoTitleLocalCacheTest extends MediaWikiIntegrationTestCase {
|
||||
class TitleLocalCacheTest extends MediaWikiIntegrationTestCase {
|
||||
|
||||
public function testCreate() {
|
||||
$cache = EchoTitleLocalCache::create();
|
||||
$this->assertInstanceOf( EchoTitleLocalCache::class, $cache );
|
||||
$cache = TitleLocalCache::create();
|
||||
$this->assertInstanceOf( TitleLocalCache::class, $cache );
|
||||
}
|
||||
|
||||
public function testAdd() {
|
||||
$cache = $this->getMockBuilder( EchoTitleLocalCache::class )
|
||||
$cache = $this->getMockBuilder( TitleLocalCache::class )
|
||||
->onlyMethods( [ 'resolve' ] )->getMock();
|
||||
|
||||
$cache->add( 1 );
|
||||
|
@ -29,15 +30,15 @@ class EchoTitleLocalCacheTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
public function testGet() {
|
||||
$cache = $this->getMockBuilder( EchoTitleLocalCache::class )
|
||||
$cache = $this->getMockBuilder( TitleLocalCache::class )
|
||||
->onlyMethods( [ 'resolve' ] )->getMock();
|
||||
$cachePriv = TestingAccessWrapper::newFromObject( $cache );
|
||||
|
||||
// First title included in cache
|
||||
$res1 = $this->insertPage( 'EchoTitleLocalCacheTest_testGet1' );
|
||||
$res1 = $this->insertPage( 'TitleLocalCacheTest_testGet1' );
|
||||
$cachePriv->targets->set( $res1['id'], $res1['title'] );
|
||||
// Second title not in internal cache, resolves from db.
|
||||
$res2 = $this->insertPage( 'EchoTitleLocalCacheTest_testGet2' );
|
||||
$res2 = $this->insertPage( 'TitleLocalCacheTest_testGet2' );
|
||||
$cache->expects( $this->once() )->method( 'resolve' )
|
||||
->with( [ $res2['id'] ] )
|
||||
->willReturn( [ $res2['id'] => $res2['title'] ] );
|
||||
|
@ -54,7 +55,7 @@ class EchoTitleLocalCacheTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
public function testClearAll() {
|
||||
$cache = $this->getMockBuilder( EchoTitleLocalCache::class )
|
||||
$cache = $this->getMockBuilder( TitleLocalCache::class )
|
||||
->onlyMethods( [ 'resolve' ] )->getMock();
|
||||
|
||||
// Add 1 to cache
|
Loading…
Reference in a new issue