jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/360817 )

Change subject: Remove label service from query used for suggestions
......................................................................


Remove label service from query used for suggestions

Removes the label service from the subquery to improve performance.
In rare cases it could change the semantics of the query for example
when label is used in filter.

Change-Id: I9e776e7978271671a4bc67d1c922a4cdecbeb3eb
---
M wikibase/queryService/ui/queryHelper/SelectorBox.js
M wikibase/queryService/ui/queryHelper/SparqlQuery.js
M wikibase/tests/queryService/ui/queryHelper/SparqlQuery.test.js
3 files changed, 72 insertions(+), 2 deletions(-)

Approvals:
  Lucas Werkmeister (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/wikibase/queryService/ui/queryHelper/SelectorBox.js 
b/wikibase/queryService/ui/queryHelper/SelectorBox.js
index 1baa166..d6bdea5 100644
--- a/wikibase/queryService/ui/queryHelper/SelectorBox.js
+++ b/wikibase/queryService/ui/queryHelper/SelectorBox.js
@@ -53,7 +53,9 @@
                                                        }\n\
                                                }\n\
                                                ORDER BY DESC(?count)',
-                                               query = 
this._query.clone().setLimit( 1000 ).getQueryString(),
+                                               query = 
this._query.clone().setLimit( 1000 )
+                                                       .removeService( 
'http://wikiba.se/ontology#label' )
+                                                       .getQueryString(),
                                                variable = 
this._query.getBoundVariables().shift(),
                                                prefixes = query.match( 
/.*\bPREFIX\b(.*)/gi ).join( '\n' );
 
@@ -134,7 +136,7 @@
                                                }\n\
                                        }\n\
                                        ORDER BY DESC(?count)',
-                                       query = this._query.clone().setLimit( 
500 ).getQueryString(),
+                                       query = this._query.clone().setLimit( 
500 ).removeService( 'http://wikiba.se/ontology#label' ).getQueryString(),
                                        variable = 
this._query.getBoundVariables().shift(),
                                        prefixes = query.match( 
/.*\bPREFIX\b(.*)/gi ).join( '\n' );
 
diff --git a/wikibase/queryService/ui/queryHelper/SparqlQuery.js 
b/wikibase/queryService/ui/queryHelper/SparqlQuery.js
index 1f3d2b9..e35d06c 100644
--- a/wikibase/queryService/ui/queryHelper/SparqlQuery.js
+++ b/wikibase/queryService/ui/queryHelper/SparqlQuery.js
@@ -298,6 +298,43 @@
        };
 
        /**
+        * Get services defined in query
+        *
+        * @return {object[]}
+        */
+       SELF.prototype.getServices = function() {
+               var services = [];
+
+               $.each( this._query.where, function( i, node ) {
+                       if ( node && node.type === 'service' ) {
+                               services.push( node );
+                       }
+
+               } );
+
+               return services;
+       };
+
+       /**
+        * Remove a certain service from the query
+        *
+        * @param {string} serviceId of the service to be removed
+        * @return {wikibase.queryService.ui.queryHelper.SparqlQuery}
+        */
+       SELF.prototype.removeService = function( serviceId ) {
+               var self = this;
+
+               $.each( this._query.where, function ( i, node ) {
+                       if ( node.type === 'service' && node.name === serviceId 
) {
+                               delete self._query.where[i];
+                       }
+
+               } );
+
+               return this;
+       };
+
+       /**
         * Get the content of a content beginning with start.
         *
         * For example, on a query with '#foo=bar',
diff --git a/wikibase/tests/queryService/ui/queryHelper/SparqlQuery.test.js 
b/wikibase/tests/queryService/ui/queryHelper/SparqlQuery.test.js
index 4efb7bf..df41033 100644
--- a/wikibase/tests/queryService/ui/queryHelper/SparqlQuery.test.js
+++ b/wikibase/tests/queryService/ui/queryHelper/SparqlQuery.test.js
@@ -13,6 +13,7 @@
                SUBQUERIES: 'SELECT * WHERE {  {SELECT * WHERE { {SELECT * 
WHERE {}} }} }',
                BOUND: 'SELECT * WHERE { ?bound <P> <O>.  OPTIONAL{ <S1> ?x 
?bound2 }  <S2> <P2> <O2>.}',
                COMMENTS: '#foo:bar\n#6*9=42\nSELECT * WHERE {  }',
+               LABEL_SERVICE: 'PREFIX wikibase: <http://wikiba.se/ontology#> 
PREFIX bd: <http://www.bigdata.com/rdf#> SELECT * WHERE { SERVICE 
wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } }',
        };
 
        QUnit.test( 'When instantiating new SparqlQuery then', function( assert 
) {
@@ -254,4 +255,34 @@
                        'six times nine must be forty-two' );
        } );
 
+       QUnit.test( 'When query is \'' + QUERY.LABEL_SERVICE + '\'', function( 
assert ) {
+               var q = new PACKAGE.SparqlQuery();
+               q.parse( QUERY.LABEL_SERVICE );
+               var s = q.getServices();
+
+               assert.equal( s.length, 1, 'There should be one service' );
+               assert.equal( s[0].name, 'http://wikiba.se/ontology#label', 
'Wikibase label service should be in services' );
+       } );
+
+       QUnit.test( 'When query is \'' + QUERY.LABEL_SERVICE + '\' and Wikibase 
label is removed', function( assert ) {
+               var q = new PACKAGE.SparqlQuery();
+               q.parse( QUERY.LABEL_SERVICE );
+               q.removeService( 'http://wikiba.se/ontology#label' );
+
+               var s = q.getServices();
+
+               assert.equal( s.length, 0, 'There should be no services' );
+       } );
+
+       QUnit.test( 'When query is \'' + QUERY.LABEL_SERVICE + '\' and some 
service is removed', function( assert ) {
+               var q = new PACKAGE.SparqlQuery();
+               q.parse( QUERY.LABEL_SERVICE );
+               q.removeService( 'SOME_SERVICE' );
+
+               var s = q.getServices();
+
+               assert.equal( s.length, 1, 'There should be one service' );
+               assert.equal( s[0].name, 'http://wikiba.se/ontology#label', 
'Wikibase label service should be in services' );
+       } );
+
 }( jQuery, QUnit, sinon, wikibase ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9e776e7978271671a4bc67d1c922a4cdecbeb3eb
Gerrit-PatchSet: 3
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to