[MediaWiki-commits] [Gerrit] Factor database access out of WikiPageEntityRevisionLookup - change (mediawiki...Wikibase)
jenkins-bot has submitted this change and it was merged. Change subject: Factor database access out of WikiPageEntityRevisionLookup .. Factor database access out of WikiPageEntityRevisionLookup Introduces WikiPageEntityMetaDataLookup which is able to retrieve the meta data that WikiPageEntityRevisionLookup needs for both accessing entities and to verify that an entity revision from cache is still the latest version. WikiPageEntityMetaDataLookup also supports getting meta data for multiple entities at once, but we're not yet making use of that. That will be used for implementing T87238. Change-Id: Ie7f76921e1d1ffd2e67c33c597e9116f2148ed3d --- M client/includes/store/sql/DirectSqlStore.php A lib/includes/store/sql/WikiPageEntityMetaDataLookup.php M lib/includes/store/sql/WikiPageEntityRevisionLookup.php M repo/includes/store/sql/SqlStore.php M repo/tests/phpunit/includes/store/WikiPageEntityRevisionLookupTest.php A repo/tests/phpunit/includes/store/sql/WikiPageEntityMetaDataLookupTest.php M repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php 7 files changed, 432 insertions(+), 194 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified diff --git a/client/includes/store/sql/DirectSqlStore.php b/client/includes/store/sql/DirectSqlStore.php index 514e3f9..8085351 100644 --- a/client/includes/store/sql/DirectSqlStore.php +++ b/client/includes/store/sql/DirectSqlStore.php @@ -25,6 +25,7 @@ use Wikibase\Lib\Store\RevisionBasedEntityLookup; use Wikibase\Lib\Store\SiteLinkLookup; use Wikibase\Lib\Store\SiteLinkTable; +use Wikibase\Lib\Store\WikiPageEntityMetaDataLookup; use Wikibase\Lib\Store\WikiPageEntityRevisionLookup; use Wikibase\Store\EntityIdLookup; @@ -311,7 +312,7 @@ $rawLookup = new WikiPageEntityRevisionLookup( $this->contentCodec, - $this->entityIdParser, + new WikiPageEntityMetaDataLookup( $this->entityIdParser, $this->repoWiki ), $this->repoWiki ); diff --git a/lib/includes/store/sql/WikiPageEntityMetaDataLookup.php b/lib/includes/store/sql/WikiPageEntityMetaDataLookup.php new file mode 100644 index 000..246566a --- /dev/null +++ b/lib/includes/store/sql/WikiPageEntityMetaDataLookup.php @@ -0,0 +1,242 @@ + + */ +class WikiPageEntityMetaDataLookup extends DBAccessBase { + + /** +* @var EntityIdParser +*/ + private $entityIdParser; + + /** +* @param EntityIdParser $entityIdParser +* @param string|bool $wiki The name of the wiki database to use (use false for the local wiki) +*/ + public function __construct( + EntityIdParser $entityIdParser, + $wiki = false + ) { + parent::__construct( $wiki ); + + // TODO: migrate table away from using a numeric field so we no longer need this! + $this->entityIdParser = $entityIdParser; + } + + /** +* @param EntityId[] $entityIds +* @param string $mode (EntityRevisionLookup::LATEST_FROM_SLAVE or EntityRevisionLookup::LATEST_FROM_MASTER) +* +* @throws DBQueryError +* @return array entity id serialization -> stdClass or false if no such entity exists +*/ + public function loadRevisionInformation( array $entityIds, $mode ) { + $rows = array(); + + if ( $mode !== EntityRevisionLookup::LATEST_FROM_MASTER ) { + $rows = $this->selectRevisionInformationMultiple( $entityIds, DB_SLAVE ); + } + + $loadFromMaster = array(); + foreach ( $entityIds as $entityId ) { + if ( !isset( $rows[$entityId->getSerialization()] ) || !$rows[$entityId->getSerialization()] ) { + $loadFromMaster[] = $entityId; + } + } + + if ( $loadFromMaster ) { + $rows = array_merge( + $rows, + $this->selectRevisionInformationMultiple( $loadFromMaster, DB_MASTER ) + ); + } + + return $rows; + } + + /** +* @param EntityId $entityId +* @param string $mode (EntityRevisionLookup::LATEST_FROM_SLAVE or EntityRevisionLookup::LATEST_FROM_MASTER) +* +* @return stdClass|false false if no such entity exists +*/ + public function loadRevisionInformationByEntityId( EntityId $entityId, $mode ) { + $rows = $this->loadRevisionInformation( array( $entityId ), $mode ); + return $rows[$entityId->getSerialization()]; + } + + /** +* @param EntityId $entityId +* @param int $revisionId +* +* @throws DBQueryErro
[MediaWiki-commits] [Gerrit] Factor database access out of WikiPageEntityRevisionLookup - change (mediawiki...Wikibase)
Hoo man has uploaded a new change for review. https://gerrit.wikimedia.org/r/200209 Change subject: Factor database access out of WikiPageEntityRevisionLookup .. Factor database access out of WikiPageEntityRevisionLookup Introduces WikiPageEntityMetaDataLookup which is able to retrieve the meta data that WikiPageEntityRevisionLookup needs for both accessing entities and to verify that an entity revision from cache is still the latest version. WikiPageEntityMetaDataLookup also supports getting meta data for multiple entities at once, but we're not yet making use of that. That will be used for implementing T87238. Change-Id: Ie7f76921e1d1ffd2e67c33c597e9116f2148ed3d --- M client/includes/store/sql/DirectSqlStore.php A lib/includes/store/sql/WikiPageEntityMetaDataLookup.php M lib/includes/store/sql/WikiPageEntityRevisionLookup.php M repo/includes/store/sql/SqlStore.php M repo/tests/phpunit/includes/store/WikiPageEntityRevisionLookupTest.php A repo/tests/phpunit/includes/store/sql/WikiPageEntityMetaDataLookupTest.php M repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php 7 files changed, 431 insertions(+), 193 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/09/200209/1 diff --git a/client/includes/store/sql/DirectSqlStore.php b/client/includes/store/sql/DirectSqlStore.php index 514e3f9..8085351 100644 --- a/client/includes/store/sql/DirectSqlStore.php +++ b/client/includes/store/sql/DirectSqlStore.php @@ -25,6 +25,7 @@ use Wikibase\Lib\Store\RevisionBasedEntityLookup; use Wikibase\Lib\Store\SiteLinkLookup; use Wikibase\Lib\Store\SiteLinkTable; +use Wikibase\Lib\Store\WikiPageEntityMetaDataLookup; use Wikibase\Lib\Store\WikiPageEntityRevisionLookup; use Wikibase\Store\EntityIdLookup; @@ -311,7 +312,7 @@ $rawLookup = new WikiPageEntityRevisionLookup( $this->contentCodec, - $this->entityIdParser, + new WikiPageEntityMetaDataLookup( $this->entityIdParser, $this->repoWiki ), $this->repoWiki ); diff --git a/lib/includes/store/sql/WikiPageEntityMetaDataLookup.php b/lib/includes/store/sql/WikiPageEntityMetaDataLookup.php new file mode 100644 index 000..246566a --- /dev/null +++ b/lib/includes/store/sql/WikiPageEntityMetaDataLookup.php @@ -0,0 +1,242 @@ + + */ +class WikiPageEntityMetaDataLookup extends DBAccessBase { + + /** +* @var EntityIdParser +*/ + private $entityIdParser; + + /** +* @param EntityIdParser $entityIdParser +* @param string|bool $wiki The name of the wiki database to use (use false for the local wiki) +*/ + public function __construct( + EntityIdParser $entityIdParser, + $wiki = false + ) { + parent::__construct( $wiki ); + + // TODO: migrate table away from using a numeric field so we no longer need this! + $this->entityIdParser = $entityIdParser; + } + + /** +* @param EntityId[] $entityIds +* @param string $mode (EntityRevisionLookup::LATEST_FROM_SLAVE or EntityRevisionLookup::LATEST_FROM_MASTER) +* +* @throws DBQueryError +* @return array entity id serialization -> stdClass or false if no such entity exists +*/ + public function loadRevisionInformation( array $entityIds, $mode ) { + $rows = array(); + + if ( $mode !== EntityRevisionLookup::LATEST_FROM_MASTER ) { + $rows = $this->selectRevisionInformationMultiple( $entityIds, DB_SLAVE ); + } + + $loadFromMaster = array(); + foreach ( $entityIds as $entityId ) { + if ( !isset( $rows[$entityId->getSerialization()] ) || !$rows[$entityId->getSerialization()] ) { + $loadFromMaster[] = $entityId; + } + } + + if ( $loadFromMaster ) { + $rows = array_merge( + $rows, + $this->selectRevisionInformationMultiple( $loadFromMaster, DB_MASTER ) + ); + } + + return $rows; + } + + /** +* @param EntityId $entityId +* @param string $mode (EntityRevisionLookup::LATEST_FROM_SLAVE or EntityRevisionLookup::LATEST_FROM_MASTER) +* +* @return stdClass|false false if no such entity exists +*/ + public function loadRevisionInformationByEntityId( EntityId $entityId, $mode ) { + $rows = $this->loadRevisionInformation( array( $entityId ), $mode ); + return $rows[$entityId->getSerialization()]; + } + + /** +* @param EntityId $entityId +* @param int $revi