Soeren.oldag has uploaded a new change for review.

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

Change subject: CrossChecker now queries external data only for properties, 
that should be validated.
......................................................................

CrossChecker now queries external data only for properties, that should be 
validated.

Change-Id: I73062843600ccac3af9d9a91b0b184844738e4fe
---
M includes/CrossCheck/CrossChecker.php
1 file changed, 36 insertions(+), 27 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQualityExternalValidation
 refs/changes/87/206087/1

diff --git a/includes/CrossCheck/CrossChecker.php 
b/includes/CrossCheck/CrossChecker.php
index 52a218c..302ab25 100644
--- a/includes/CrossCheck/CrossChecker.php
+++ b/includes/CrossCheck/CrossChecker.php
@@ -107,24 +107,25 @@
                        }
                }
 
-        $this->establishDbConnection();
+        $resultList = new CrossCheckResultList();
+        if( $statements->count() > 0 ) {
+            $this->establishDbConnection();
+            $applicableDumpIds = $this->getApplicableDumpIds( $this->entity );
 
-               $applicableDumpIds = $this->getApplicableDumpIds( $this->entity 
);
+            foreach ( $applicableDumpIds as $identifierPropertyId => $dumpIds 
) {
+                $identifierPropertyId = new PropertyId( $identifierPropertyId 
);
 
-               $resultList = new CrossCheckResultList();
-               foreach ( $applicableDumpIds as $identifierPropertyId => 
$dumpIds ) {
-                       $identifierPropertyId = new PropertyId( 
$identifierPropertyId );
+                $resultList->merge(
+                    $this->crossCheckStatementsWithIdentifier(
+                        $statements,
+                        $identifierPropertyId,
+                        $dumpIds
+                    )
+                );
+            }
 
-                       $resultList->merge(
-                               $this->crossCheckStatementsWithIdentifier(
-                                       $statements,
-                                       $identifierPropertyId,
-                                       $dumpIds
-                               )
-                       );
-               }
-
-        $this->reuseDbConnection();
+            $this->reuseDbConnection();
+        }
 
                return $resultList;
        }
@@ -141,7 +142,7 @@
        private function crossCheckStatementsWithIdentifier( StatementList 
$statements, PropertyId $identifierPropertyId, array $dumpIds ) {
                $externalIds = $this->getExternalIds( $identifierPropertyId );
 
-               $externalData = $this->getExternalData( $dumpIds, $externalIds 
);
+               $externalData = $this->getExternalData( $dumpIds, $externalIds, 
$statements );
 
                $resultList = new CrossCheckResultList();
                foreach ( $externalData as $dumpId => $externalDataPerDump ) {
@@ -257,14 +258,15 @@
        }
 
        /**
-        * Gets external data from database that matches any combination of 
given dump and external ids
+        * Gets external data for specified properties from database that 
matches any combination of given dump and external ids
         *
         * @param array $dumpIds
         * @param array $externalIds
+     * @param StatementList $statements
         *
         * @return array
         */
-       private function getExternalData( array $dumpIds, array $externalIds ) {
+       private function getExternalData( array $dumpIds, array $externalIds, 
StatementList $statements ) {
                $externalData = array ();
                if ( $dumpIds && $externalIds ) {
                        $result = $this->db->select(
@@ -277,7 +279,8 @@
                                ),
                                array (
                                        $this->buildSqlInCondition( 'dump_id', 
$dumpIds ),
-                                       $this->buildSqlInCondition( 
'external_id', $externalIds )
+                                       $this->buildSqlInCondition( 
'external_id', $externalIds ),
+                    $this->buildSqlInCondition( 'pid', 
$statements->getPropertyIds() )
                                )
                        );
 
@@ -290,7 +293,8 @@
        }
 
        /**
-        * Creates SQL condition for WHERE clauses using the IN operator
+        * Creates SQL condition for WHERE clauses using the IN operator.
+     * If $values is empty, true will be returned.
         *
         * @param string $columnName
         * @param array $values
@@ -298,14 +302,19 @@
         * @return string
         */
        private static function buildSqlInCondition( $columnName, array $values 
) {
-               $values = array_map(
-                       function ( $value ) {
-                               return sprintf( '"%s"', $value );
-                       },
-                       $values
-               );
+        if( count($values) > 0 ) {
+            $values = array_map(
+                function ( $value ) {
+                    return sprintf( '"%s"', $value );
+                },
+                $values
+            );
 
-               return sprintf( '%s in (%s)', $columnName, implode( ',', 
$values ) );
+            return sprintf( '%s in (%s)', $columnName, implode( ',', $values ) 
);
+        }
+        else {
+            return 'true';
+        }
        }
 
     /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I73062843600ccac3af9d9a91b0b184844738e4fe
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataQualityExternalValidation
Gerrit-Branch: master
Gerrit-Owner: Soeren.oldag <soeren_ol...@freenet.de>

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

Reply via email to