Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/94686


Change subject: Add profiling calls to TermSqlIndex
......................................................................

Add profiling calls to TermSqlIndex

Change-Id: Ia7151f204f02e589cf343b2d9f5b8f0216955f2d
---
M lib/includes/store/sql/TermSqlIndex.php
1 file changed, 66 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/86/94686/1

diff --git a/lib/includes/store/sql/TermSqlIndex.php 
b/lib/includes/store/sql/TermSqlIndex.php
index 6a73a23..5c6311f 100644
--- a/lib/includes/store/sql/TermSqlIndex.php
+++ b/lib/includes/store/sql/TermSqlIndex.php
@@ -97,6 +97,8 @@
         * @return boolean Success indicator
         */
        public function saveTermsOfEntity( Entity $entity ) {
+               wfProfileIn( __METHOD__ );
+
                //First check whether there's anything to update
                $newTerms = $entity->getTerms();
                $oldTerms = $this->getTermsOfEntity( $entity->getId() );
@@ -119,6 +121,7 @@
 
                        if ( $equal ) {
                                wfDebugLog( __CLASS__, __FUNCTION__ . ": terms 
did not change, returning." );
+                               wfProfileOut( __METHOD__ );
                                return true; // nothing to do.
                        }
                }
@@ -128,6 +131,8 @@
 
                $ok = $dbw->deadlockLoop( array( $this, 
'saveTermsOfEntityInternal' ), $entity, $dbw );
                $this->releaseConnection( $dbw );
+
+               wfProfileOut( __METHOD__ );
 
                return $ok;
        }
@@ -146,6 +151,8 @@
         * @return boolean Success indicator
         */
        public function saveTermsOfEntityInternal( Entity $entity, DatabaseBase 
$dbw ) {
+               wfProfileIn( __METHOD__ );
+
                $entityIdentifiers = array(
                        'term_entity_id' => $entity->getId()->getNumericId(),
                        'term_entity_type' => $entity->getType()
@@ -184,6 +191,8 @@
                                break;
                        }
                }
+
+               wfProfileOut( __METHOD__ );
 
                return $success;
        }
@@ -242,6 +251,8 @@
         * @return boolean Success indicator
         */
        public function deleteTermsOfEntity( Entity $entity ) {
+               wfProfileIn( __METHOD__ );
+
                $dbw = $this->getConnection( DB_MASTER );
 
                //TODO: do this via deadlockLoop. Currently triggers warnings, 
because deleteTermsOfEntity
@@ -254,6 +265,8 @@
 
                $ok = $this->deleteTermsOfEntityInternal( $entity, $dbw );
                $this->releaseConnection( $dbw );
+
+               wfProfileOut( __METHOD__ );
 
                return $ok;
        }
@@ -295,6 +308,8 @@
         * @return Term[]
         */
        public function getTermsOfEntity( EntityId $id ) {
+               wfProfileIn( __METHOD__ );
+
                $entityIdentifiers = array(
                        'term_entity_id' => $id->getNumericId(),
                        'term_entity_type' => $id->getEntityType()
@@ -318,6 +333,9 @@
                $terms = $this->buildTermResult( $res );
 
                $this->releaseConnection( $dbr );
+
+               wfProfileOut( __METHOD__ );
+
                return $terms;
        }
 
@@ -330,10 +348,12 @@
         * @param string $entityType
         * @param string|null $language Language code
         *
-        * @throws \MWException
+        * @throws MWException
         * @return Term[]
         */
        public function getTermsOfEntities( array $ids, $entityType, $language 
= null ) {
+               wfProfileIn( __METHOD__ );
+
                if ( empty($ids) ) {
                        return array();
                }
@@ -348,7 +368,7 @@
                $numericIds = array();
                foreach ( $ids as $id ) {
                        if ( $id->getEntityType() !== $entityType ) {
-                               throw new \MWException( "ID " . 
$id->getPrefixedId()
+                               throw new MWException( "ID " . 
$id->getPrefixedId()
                                        . " does not refer to an entity of type 
$entityType." );
                        }
 
@@ -377,6 +397,9 @@
                $terms = $this->buildTermResult( $res );
 
                $this->releaseConnection( $dbr );
+
+               wfProfileOut( __METHOD__ );
+
                return $terms;
        }
 
@@ -415,6 +438,8 @@
         * @return boolean
         */
        public function termExists( $termValue, $termType = null, $termLanguage 
= null, $entityType = null ) {
+               wfProfileIn( __METHOD__ );
+
                $conditions = array(
                        'term_text' => $termValue,
                );
@@ -443,6 +468,9 @@
                );
 
                $this->releaseConnection( $dbr );
+
+               wfProfileOut( __METHOD__ );
+
                return $result !== false;
        }
 
@@ -460,6 +488,8 @@
         * @return array of array( entity type, entity id )
         */
        public function getEntityIdsForLabel( $label, $languageCode = null, 
$description = null, $entityType = null, $fuzzySearch = false ) {
+               wfProfileIn( __METHOD__ );
+
                $fuzzySearch = false; // TODO switched off for now until we 
have a solution for limiting the results
                $db = $this->getReadDb();
 
@@ -512,12 +542,16 @@
 
                $this->releaseConnection( $db );
 
-               return array_map(
+               $result = array_map(
                        function( $entity ) {
                                return array( $entity->term_entity_type, 
intval( $entity->term_entity_id ) );
                        },
                        iterator_to_array( $entities )
                );
+
+               wfProfileOut( __METHOD__ );
+
+               return $result;
        }
 
        /**
@@ -533,7 +567,10 @@
         * @return array
         */
        public function getMatchingTerms( array $terms, $termType = null, 
$entityType = null, array $options = array() ) {
+               wfProfileIn( __METHOD__ );
+
                if ( empty( $terms ) ) {
+                       wfProfileOut( __METHOD__ );
                        return array();
                }
 
@@ -560,6 +597,9 @@
                $terms = $this->buildTermResult( $obtainedTerms );
 
                $this->releaseConnection( $dbr );
+
+               wfProfileOut( __METHOD__ );
+
                return $terms;
        }
 
@@ -575,7 +615,10 @@
         * @return EntityId[]
         */
        public function getMatchingIDs( array $terms, $entityType, array 
$options = array() ) {
+               wfProfileIn( __METHOD__ );
+
                if ( empty( $terms ) ) {
+                       wfProfileOut( __METHOD__ );
                        return array();
                }
 
@@ -653,6 +696,8 @@
                        $result[] = $idParser->parse( $id->getSerialization() );
                }
 
+               wfProfileOut( __METHOD__ );
+
                return $result;
        }
 
@@ -670,6 +715,8 @@
         * @return array
         */
        protected function termsToConditions( array $terms, $termType, 
$entityType, $forJoin = false, array $options = array() ) {
+               wfProfileIn( __METHOD__ );
+
                $options = array_merge(
                        array(
                                'caseSensitive' => true,
@@ -746,6 +793,9 @@
                }
 
                $this->releaseConnection( $dbr );
+
+               wfProfileOut( __METHOD__ );
+
                return $conditions;
        }
 
@@ -760,6 +810,8 @@
         * @return array
         */
        protected function buildTermResult( $obtainedTerms ) {
+               wfProfileIn( __METHOD__ );
+
                $matchingTerms = array();
 
                foreach ( $obtainedTerms as $obtainedTerm ) {
@@ -780,6 +832,8 @@
 
                        $matchingTerms[] = new Term( $matchingTerm );
                }
+
+               wfProfileOut( __METHOD__ );
 
                return $matchingTerms;
        }
@@ -814,7 +868,10 @@
         * @return array
         */
        public function getMatchingTermCombination( array $terms, $termType = 
null, $entityType = null, EntityId $excludeId = null ) {
+               wfProfileIn( __METHOD__ );
+
                if ( empty( $terms ) ) {
+                       wfProfileOut( __METHOD__ );
                        return array();
                }
 
@@ -878,6 +935,9 @@
                $terms = $this->buildTermResult( 
$this->getNormalizedJoinResult( $obtainedTerms, $joinCount ) );
 
                $this->releaseConnection( $dbr );
+
+               wfProfileOut( __METHOD__ );
+
                return $terms;
        }
 
@@ -895,7 +955,7 @@
         *
         * @return array
         */
-       protected function getNormalizedJoinResult( \ResultWrapper 
$obtainedTerms, $joinCount ) {
+       protected function getNormalizedJoinResult( ResultWrapper 
$obtainedTerms, $joinCount ) {
                $resultTerms = array();
 
                foreach ( $obtainedTerms as $obtainedTerm ) {
@@ -919,6 +979,8 @@
                        }
                }
 
+               wfProfileOut( __METHOD__ );
+
                return $resultTerms;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/94686
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia7151f204f02e589cf343b2d9f5b8f0216955f2d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to