jenkins-bot has submitted this change and it was merged.

Change subject: SolrTTMServer: corner case tweaks
......................................................................


SolrTTMServer: corner case tweaks

Wrap whole query into try-catch, because if the request times
out, exception can be thrown when iterating the results, not
only when executing the query. Also impose a random max limit
on the query string length for now.

Bug: 43778
Change-Id: I10ad6aded1dcab68f453767c08ba1dd77e2302d9
---
M ttmserver/SolrTTMServer.php
1 file changed, 19 insertions(+), 11 deletions(-)

Approvals:
  Siebrand: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ttmserver/SolrTTMServer.php b/ttmserver/SolrTTMServer.php
index 972a0d4..8fe26a5 100644
--- a/ttmserver/SolrTTMServer.php
+++ b/ttmserver/SolrTTMServer.php
@@ -38,11 +38,27 @@
        }
 
        public function query( $sourceLanguage, $targetLanguage, $text ) {
+               try {
+                       return $this->doQuery( $sourceLanguage, 
$targetLanguage, $text );
+               } catch ( Solarium_Exception $e ) {
+                       throw new TranslationHelperException( 'Solarium 
exception: ' . $e );
+               }
+       }
+
+       /// @see ReadableTTMServer::query
+       protected function doQuery( $sourceLanguage, $targetLanguage, $text ) {
                /* Two query system:
                 * 1) Find all strings in source language that match text
                 * 2) Do another query for translations for those strings
                 */
                wfProfileIn( __METHOD__ );
+               // For now impose a length limit on query string to avoid doing
+               // very slow queries. Magic number.
+               if ( strlen( $text ) > 789 ) {
+                       return array();
+               }
+
+
                $query = $this->client->createSelect();
                $query->setFields( array( 'globalid', 'content', 'score' ) );
 
@@ -70,12 +86,8 @@
                $query->createFilterQuery( 'lang' )
                        ->setQuery( 'language:%P1%', array( $sourceLanguage ) );
 
-               // Converting Solarium exceptions to our exceptions
-               try {
-                       $resultset = $this->client->select( $query );
-               } catch ( Solarium_Exception $e ) {
-                       throw new TranslationHelperException( 'Solarium 
exception: ' . $e );
-               }
+
+               $resultset = $this->client->select( $query );
 
                /* This query is doing two unrelated things:
                 * 1) Collect the message contents and scores so that they can
@@ -105,11 +117,7 @@
                // With AND we would not find anything, obviously.
                $fetchQuery->setQueryDefaultOperator( 
Solarium_Query_Select::QUERY_OPERATOR_OR );
 
-               try {
-                       $translations = $this->client->select( $fetchQuery );
-               } catch ( Solarium_Exception $e ) {
-                       throw new TranslationHelperException( 'Solarium 
exception: ' . $e );
-               }
+               $translations = $this->client->select( $fetchQuery );
 
                $suggestions = array();
                foreach ( $translations as $doc ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I10ad6aded1dcab68f453767c08ba1dd77e2302d9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to