jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/353870 )
Change subject: Make MAX_ENTITIES configurable and raise default ...................................................................... Make MAX_ENTITIES configurable and raise default The limit should be configurable, since different projects with different class hierarchy conventions will need different values. For Wikidata, the old limit of 50 was rather low (it is common to have several, partially redundant superclass: city, big city, metropolis, …), so the default is raised as well. Hopefully, we will soon be able to use a SPARQL-based type checker instead; in that case, this limit will probably become the point at which the checker switches from direct supertype traversal to SPARQL checking, and a lower value will be more appropriate. The DefaultConfig trait for tests reduces the limit to make the tests run a bit faster. Bug: T164948 Change-Id: Ic5bf0f5453121f8b77e8616ba717b22fea8192e9 --- M extension.json M includes/ConstraintCheck/Helper/TypeCheckerHelper.php M tests/phpunit/Checker/TypeChecker/TypeCheckerHelperTest.php M tests/phpunit/DefaultConfig.php 4 files changed, 14 insertions(+), 6 deletions(-) Approvals: jenkins-bot: Verified Thiemo Mättig (WMDE): Looks good to me, approved diff --git a/extension.json b/extension.json index b47be26..1f5ac61 100644 --- a/extension.json +++ b/extension.json @@ -50,6 +50,11 @@ } }, "config": { + "WBQualityConstraintsTypeCheckMaxEntities": { + "value": 1000, + "description": "The maximum number of entities that are accessed when checking type or subtype relations.", + "public": true + }, "WBQualityConstraintsInstanceOfId": { "value": "P31", "description": "The property ID of the 'instance of' property, which specifies the class(es) of an item.", diff --git a/includes/ConstraintCheck/Helper/TypeCheckerHelper.php b/includes/ConstraintCheck/Helper/TypeCheckerHelper.php index 2ca7f6d..5bcc6dd 100644 --- a/includes/ConstraintCheck/Helper/TypeCheckerHelper.php +++ b/includes/ConstraintCheck/Helper/TypeCheckerHelper.php @@ -25,8 +25,6 @@ */ class TypeCheckerHelper { - const MAX_ENTITIES = 50; - /** * @var EntityLookup */ @@ -60,7 +58,8 @@ /** * Checks if $comparativeClass is a subclass * of one of the item ID serializations in $classesToCheck. - * If the class hierarchy is not exhausted after checking MAX_ENTITIES entities, + * If the class hierarchy is not exhausted before + * the configured limit (WBQualityConstraintsTypeCheckMaxEntities) is reached, * the check aborts and returns false. * * @param EntityId $comparativeClass @@ -70,7 +69,7 @@ * @return bool */ public function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { - if ( ++$entitiesChecked > self::MAX_ENTITIES ) { + if ( ++$entitiesChecked > $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ) ) { return false; } diff --git a/tests/phpunit/Checker/TypeChecker/TypeCheckerHelperTest.php b/tests/phpunit/Checker/TypeChecker/TypeCheckerHelperTest.php index e659d53..89baa0d 100644 --- a/tests/phpunit/Checker/TypeChecker/TypeCheckerHelperTest.php +++ b/tests/phpunit/Checker/TypeChecker/TypeCheckerHelperTest.php @@ -41,13 +41,15 @@ } /** - * @return EntityLookup Expects that getEntity is called exactly MAX_ENTITIES times. + * @return EntityLookup Expects that getEntity is called + * exactly WBQualityConstraintsTypeCheckMaxEntities times. */ private function getMaxEntitiesLookup() { $lookup = new JsonFileEntityLookup( __DIR__ ); + $maxEntities = $this->getDefaultConfig()->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); $spy = $this->getMock( EntityLookup::class ); - $spy->expects( $this->exactly( TypeCheckerHelper::MAX_ENTITIES ) ) + $spy->expects( $this->exactly( $maxEntities ) ) ->method( 'getEntity' ) ->will( $this->returnCallback( [ $lookup, 'getEntity' ] ) ); diff --git a/tests/phpunit/DefaultConfig.php b/tests/phpunit/DefaultConfig.php index 8bb7ce1..cc49b92 100644 --- a/tests/phpunit/DefaultConfig.php +++ b/tests/phpunit/DefaultConfig.php @@ -24,6 +24,8 @@ foreach ( $extensionJson['config'] as $key => $value ) { $this->defaultConfig->set( $key, $value['value'] ); } + // reduce some limits to make tests run faster + $this->defaultConfig->set( 'WBQualityConstraintsTypeCheckMaxEntities', 10 ); } return $this->defaultConfig; -- To view, visit https://gerrit.wikimedia.org/r/353870 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic5bf0f5453121f8b77e8616ba717b22fea8192e9 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints Gerrit-Branch: master Gerrit-Owner: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de> Gerrit-Reviewer: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits