Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/175803
Change subject: Narrow TermSqlIndex interface to EntityId ...................................................................... Narrow TermSqlIndex interface to EntityId Change-Id: I179e1f4f6794819c7497dc8b33579ea0720c10b8 --- M lib/includes/store/sql/TermSqlIndex.php 1 file changed, 21 insertions(+), 26 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/03/175803/1 diff --git a/lib/includes/store/sql/TermSqlIndex.php b/lib/includes/store/sql/TermSqlIndex.php index 1ec6880..4b5a54a 100644 --- a/lib/includes/store/sql/TermSqlIndex.php +++ b/lib/includes/store/sql/TermSqlIndex.php @@ -105,7 +105,7 @@ $termsToDelete = array_udiff( $oldTerms, $newTerms, 'Wikibase\Term::compare' ); if ( !$termsToInsert && !$termsToDelete ) { - wfDebugLog( __CLASS__, __FUNCTION__ . ": terms did not change, returning." ); + wfDebugLog( __CLASS__, __FUNCTION__ . ': terms did not change, returning.' ); wfProfileOut( __METHOD__ ); return true; } @@ -114,18 +114,13 @@ $dbw = $this->getConnection( DB_MASTER ); if ( $ok && $termsToDelete ) { - wfDebugLog( __CLASS__, __FUNCTION__ . ": " . count( $termsToDelete ) . " terms to delete." ); - $ok = $dbw->deadlockLoop( array( $this, 'deleteTermsInternal' ), $entity, $termsToDelete, $dbw ); + wfDebugLog( __CLASS__, __FUNCTION__ . ': ' . count( $termsToDelete ) . ' terms to delete.' ); + $ok = $dbw->deadlockLoop( array( $this, 'deleteTermsInternal' ), $entity->getId(), $termsToDelete, $dbw ); } if ( $ok && $termsToInsert ) { - wfDebugLog( __CLASS__, __FUNCTION__ . ": " . count( $termsToInsert ) . " terms to insert." ); - - // TODO: remove silly self hack when we can use PHP 5.4 - $self = $this; - $ok = $dbw->deadlockLoop( function() use ( $self, $entity, $termsToInsert, $dbw ) { - return $self->insertTermsInternal( $entity, $termsToInsert, $dbw ); - } ); + wfDebugLog( __CLASS__, __FUNCTION__ . ': ' . count( $termsToInsert ) . ' terms to insert.' ); + $ok = $dbw->deadlockLoop( array( $this, 'insertTermsInternal' ), $entity, $termsToInsert, $dbw ); } $this->releaseConnection( $dbw ); @@ -250,26 +245,26 @@ * * @since 0.5 * - * @param EntityDocument $entity + * @param EntityId $entityId * @param Term[] $terms * @param DatabaseBase $dbw * * @return boolean Success indicator */ - public function deleteTermsInternal( EntityDocument $entity, $terms, DatabaseBase $dbw ) { + public function deleteTermsInternal( EntityId $entityId, $terms, DatabaseBase $dbw ) { wfProfileIn( __METHOD__ ); //TODO: Make getTermsOfEntity() collect term_row_id values, so we can use them here. // That would allow us to do the deletion in a single query, based on a set of ids. $entityIdentifiers = array( - 'term_entity_id' => $entity->getId()->getNumericId(), - 'term_entity_type' => $entity->getId()->getEntityType() + 'term_entity_id' => $entityId->getNumericId(), + 'term_entity_type' => $entityId->getEntityType() ); $uniqueKeyFields = array( 'term_entity_type', 'term_entity_id', 'term_language', 'term_type', 'term_text' ); - wfDebugLog( __CLASS__, __FUNCTION__ . ': deleting terms for ' . $entity->getId()->getSerialization() ); + wfDebugLog( __CLASS__, __FUNCTION__ . ': deleting terms for ' . $entityId->getSerialization() ); $success = true; foreach ( $terms as $term ) { @@ -378,16 +373,16 @@ * Returns the terms stored for the given entity. * @see TermIndex::getTermsOfEntity * - * @param EntityId $id + * @param EntityId $entityId * * @return Term[] */ - public function getTermsOfEntity( EntityId $id ) { + public function getTermsOfEntity( EntityId $entityId ) { wfProfileIn( __METHOD__ ); $entityIdentifiers = array( - 'term_entity_id' => $id->getNumericId(), - 'term_entity_type' => $id->getEntityType() + 'term_entity_id' => $entityId->getNumericId(), + 'term_entity_type' => $entityId->getEntityType() ); $fields = array( @@ -419,17 +414,17 @@ * * @see TermIndex::getTermsOfEntities * - * @param EntityId[] $ids + * @param EntityId[] $entityIds * @param string $entityType * @param string|null $language Language code * * @throws MWException * @return Term[] */ - public function getTermsOfEntities( array $ids, $entityType, $language = null ) { + public function getTermsOfEntities( array $entityIds, $entityType, $language = null ) { wfProfileIn( __METHOD__ ); - if ( empty($ids) ) { + if ( empty( $entityIds ) ) { wfProfileOut( __METHOD__ ); return array(); } @@ -442,13 +437,13 @@ } $numericIds = array(); - foreach ( $ids as $id ) { - if ( $id->getEntityType() !== $entityType ) { - throw new MWException( 'ID ' . $id->getSerialization() + foreach ( $entityIds as $entityId ) { + if ( $entityId->getEntityType() !== $entityType ) { + throw new MWException( 'ID ' . $entityId->getSerialization() . " does not refer to an entity of type $entityType." ); } - $numericIds[] = $id->getNumericId(); + $numericIds[] = $entityId->getNumericId(); } $entityIdentifiers['term_entity_id'] = $numericIds; -- To view, visit https://gerrit.wikimedia.org/r/175803 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I179e1f4f6794819c7497dc8b33579ea0720c10b8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits