WMDE-leszek has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/357812 )
Change subject: Allow setting the start position of SqlEntityIdPager
......................................................................
Allow setting the start position of SqlEntityIdPager
E.g. in order to re-start fetching entity IDs from the given point.
Change-Id: I040124d988d9eee4a3da3338287f2b7169036c8f
---
M repo/includes/Store/Sql/SqlEntityIdPager.php
M repo/tests/phpunit/includes/Store/Sql/SqlEntityIdPagerTest.php
2 files changed, 83 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/12/357812/1
diff --git a/repo/includes/Store/Sql/SqlEntityIdPager.php
b/repo/includes/Store/Sql/SqlEntityIdPager.php
index 8f9e932..b68febb 100644
--- a/repo/includes/Store/Sql/SqlEntityIdPager.php
+++ b/repo/includes/Store/Sql/SqlEntityIdPager.php
@@ -116,6 +116,20 @@
}
/**
+ * @return int
+ */
+ public function getPosition() {
+ return $this->position;
+ }
+
+ /**
+ * @param int $position
+ */
+ public function setPosition( $position ) {
+ $this->position = $position;
+ }
+
+ /**
* @param int $position
*
* @return array
diff --git a/repo/tests/phpunit/includes/Store/Sql/SqlEntityIdPagerTest.php
b/repo/tests/phpunit/includes/Store/Sql/SqlEntityIdPagerTest.php
index 464a827..2505fbf 100644
--- a/repo/tests/phpunit/includes/Store/Sql/SqlEntityIdPagerTest.php
+++ b/repo/tests/phpunit/includes/Store/Sql/SqlEntityIdPagerTest.php
@@ -3,6 +3,7 @@
namespace Wikibase\Repo\Tests\Store\Sql;
use MediaWikiTestCase;
+use Wikibase\DataModel\Entity\BasicEntityIdParser;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\EntityRedirect;
@@ -11,7 +12,9 @@
use Wikibase\DataModel\Entity\Property;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Services\EntityId\EntityIdPager;
+use Wikibase\Lib\Store\EntityNamespaceLookup;
use Wikibase\Repo\Store\Sql\SqlEntityIdPager;
+use Wikibase\Repo\Store\WikiPageEntityStore;
use Wikibase\Repo\WikibaseRepo;
/**
@@ -258,4 +261,70 @@
];
}
+ public function testSetPosition() {
+ $property = new Property( new PropertyId( 'P1' ), null,
'string' );
+ $item = new Item( new ItemId( 'Q5' ) );
+
+ $this->insertEntities( [ $property, $item ] );
+
+ $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+ $pager = new SqlEntityIdPager(
+ $wikibaseRepo->getEntityNamespaceLookup(),
+ $wikibaseRepo->getEntityIdParser()
+ );
+
+ $ids = $pager->fetchIds( 2 );
+
+ $this->assertCount( 2, $ids );
+
+ /** @var WikiPageEntityStore $entityStore */
+ $entityStore = $wikibaseRepo->getEntityStore();
+
+ $propertyPage = $entityStore->getWikiPageForEntity(
$property->getId() );
+
+ $pager->setPosition( $propertyPage->getId() );
+
+ $ids = $pager->fetchIds( 2 );
+
+ $this->assertCount( 1, $ids );
+
+ $this->assertEquals( new ItemId( 'Q5' ), $ids[0] );
+ }
+
+ public function testGetPositionReturnsZeroWhenNothingFetchedYet() {
+ $entityNamespaceLookup = $this->getMockBuilder(
EntityNamespaceLookup::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $pager = new SqlEntityIdPager(
+ $entityNamespaceLookup,
+ new BasicEntityIdParser()
+ );
+
+ $this->assertSame( 0, $pager->getPosition() );
+ }
+
+ public function testGetPositionReturnsPageIdOfLastFetchedEntity() {
+ $property = new Property( new PropertyId( 'P1' ), null,
'string' );
+ $item = new Item( new ItemId( 'Q5' ) );
+
+ $this->insertEntities( [ $property, $item ] );
+
+ $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+
+ /** @var WikiPageEntityStore $entityStore */
+ $entityStore = $wikibaseRepo->getEntityStore();
+
+ $itemPage = $entityStore->getWikiPageForEntity( $item->getId()
);
+
+ $pager = new SqlEntityIdPager(
+ $wikibaseRepo->getEntityNamespaceLookup(),
+ $wikibaseRepo->getEntityIdParser()
+ );
+
+ $pager->fetchIds( 100 );
+
+ $this->assertSame( $itemPage->getId(), $pager->getPosition() );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/357812
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I040124d988d9eee4a3da3338287f2b7169036c8f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: WMDE-leszek <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits