Hoo man has uploaded a new change for review.

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

Change subject: Use one query per term type in 
SqlEntityInfoBuilder::collectTermsForEntities
......................................................................

Use one query per term type in SqlEntityInfoBuilder::collectTermsForEntities

This is way faster on MySQL, see T147748#2711717 for benchmarks.

Bug: T147748
Change-Id: Ide5dc20cfd0ce7b4a3d465495dc7be91c87159b6
---
M lib/includes/Store/Sql/SqlEntityInfoBuilder.php
M lib/tests/phpunit/Store/EntityInfoBuilderTest.php
2 files changed, 43 insertions(+), 12 deletions(-)


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

diff --git a/lib/includes/Store/Sql/SqlEntityInfoBuilder.php 
b/lib/includes/Store/Sql/SqlEntityInfoBuilder.php
index 0fe4b65..337f5b1 100644
--- a/lib/includes/Store/Sql/SqlEntityInfoBuilder.php
+++ b/lib/includes/Store/Sql/SqlEntityInfoBuilder.php
@@ -351,8 +351,8 @@
                        'term_entity_id' => $entityIds,
                );
 
-               if ( $termTypes ) {
-                       $where['term_type'] = $termTypes;
+               if ( $termTypes === null ) {
+                       $termTypes = [ null ];
                }
 
                if ( $languages ) {
@@ -361,14 +361,17 @@
 
                $dbw = $this->getConnection( DB_SLAVE );
 
-               $res = $dbw->select(
-                       $this->termTable,
-                       array( 'term_entity_type', 'term_entity_id', 
'term_type', 'term_language', 'term_text' ),
-                       $where,
-                       __METHOD__
-               );
+               // Do one query per term type here, this is way faster on 
MySQL: T147748
+               foreach ( $termTypes as $termType ) {
+                       $res = $dbw->select(
+                               $this->termTable,
+                               array( 'term_entity_type', 'term_entity_id', 
'term_type', 'term_language', 'term_text' ),
+                               array_merge( $where, $termType !== null ? [ 
'term_type' => $termType ] : [] ),
+                               __METHOD__
+                       );
 
-               $this->injectTerms( $res );
+                       $this->injectTerms( $res );
+               }
 
                $this->releaseConnection( $dbw );
        }
diff --git a/lib/tests/phpunit/Store/EntityInfoBuilderTest.php 
b/lib/tests/phpunit/Store/EntityInfoBuilderTest.php
index 8b3730a..c3c59da 100644
--- a/lib/tests/phpunit/Store/EntityInfoBuilderTest.php
+++ b/lib/tests/phpunit/Store/EntityInfoBuilderTest.php
@@ -189,14 +189,14 @@
 
        public function collectTermsProvider() {
                return array(
-                       array(
+                       'empty set' => array(
                                array(),
                                null,
                                null,
                                array()
                        ),
 
-                       array(
+                       'all term types' => array(
                                array(
                                        new ItemId( 'Q1' ),
                                        new PropertyId( 'P3' ),
@@ -229,7 +229,7 @@
                                )
                        ),
 
-                       array(
+                       'one term type' => array(
                                array(
                                        new ItemId( 'Q1' ),
                                        new PropertyId( 'P3' ),
@@ -247,6 +247,34 @@
                                        'Q7' => array( 'id' => 'Q7', 'type' => 
Item::ENTITY_TYPE, 'labels' => array() ),
                                )
                        ),
+
+                       'two term types' => array(
+                               array(
+                                       new ItemId( 'Q1' ),
+                                       new PropertyId( 'P3' ),
+                                       new ItemId( 'Q7' ),
+                               ),
+                               array( 'label', 'description' ),
+                               null,
+                               array(
+                                       'Q1' => array( 'id' => 'Q1', 'type' => 
Item::ENTITY_TYPE,
+                                               'labels' => 
$this->makeLanguageValueRecords( array(
+                                                       'en' => 'label:Q1/en', 
'de' => 'label:Q1/de' ) ),
+                                               'descriptions' => 
$this->makeLanguageValueRecords( array(
+                                                       'en' => 
'description:Q1/en', 'de' => 'description:Q1/de' ) )
+                                       ),
+                                       'P3' => array( 'id' => 'P3', 'type' => 
Property::ENTITY_TYPE,
+                                               'labels' => 
$this->makeLanguageValueRecords( array(
+                                                       'en' => 'label:P3/en', 
'de' => 'label:P3/de' ) ),
+                                               'descriptions' => 
$this->makeLanguageValueRecords( array(
+                                                       'en' => 
'description:P3/en', 'de' => 'description:P3/de' ) )
+                                       ),
+                                       'Q7' => array( 'id' => 'Q7', 'type' => 
Item::ENTITY_TYPE,
+                                               'labels' => array(),
+                                               'descriptions' => array()
+                                       ),
+                               )
+                       ),
                );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ide5dc20cfd0ce7b4a3d465495dc7be91c87159b6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <h...@online.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to