jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/404973 )
Change subject: Issue a warning when entity usage per page passes a limit ...................................................................... Issue a warning when entity usage per page passes a limit Bug: T184319 Change-Id: Ic413621d94e19126f63e35f4660d5ed63e927076 --- M client/config/WikibaseClient.default.php M client/includes/Store/Sql/DirectSqlStore.php M client/includes/Usage/Sql/SqlUsageTracker.php M client/includes/WikibaseClient.php M client/tests/phpunit/includes/Store/Sql/DirectSqlStoreTest.php M client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php M docs/options.wiki 7 files changed, 48 insertions(+), 10 deletions(-) Approvals: WMDE-leszek: Looks good to me, approved jenkins-bot: Verified diff --git a/client/config/WikibaseClient.default.php b/client/config/WikibaseClient.default.php index f05fcec..a7ae48f 100644 --- a/client/config/WikibaseClient.default.php +++ b/client/config/WikibaseClient.default.php @@ -246,5 +246,8 @@ // Disabled entity access $defaults['disabledAccessEntityTypes'] = []; + // The limit to issue a warning when number of entities used in a page hit that + $defaults['entityUsagePerPageLimit'] = 100; + return $defaults; } ); diff --git a/client/includes/Store/Sql/DirectSqlStore.php b/client/includes/Store/Sql/DirectSqlStore.php index 6c0fc7b..1a02f27 100644 --- a/client/includes/Store/Sql/DirectSqlStore.php +++ b/client/includes/Store/Sql/DirectSqlStore.php @@ -8,6 +8,7 @@ use Wikibase\Client\Store\ClientStore; use Wikibase\Lib\Store\CachingPropertyInfoLookup; use Wikibase\Lib\Store\PropertyInfoLookup; +use Wikibase\SettingsArray; use Wikibase\StringNormalizer; use Wikibase\TermIndex; use Wikibase\Lib\Store\TermPropertyLabelResolver; @@ -19,7 +20,6 @@ use Wikibase\Client\Usage\SubscriptionManager; use Wikibase\Client\Usage\UsageLookup; use Wikibase\Client\Usage\UsageTracker; -use Wikibase\Client\WikibaseClient; use Wikibase\DataAccess\WikibaseServices; use Wikibase\DataModel\Entity\EntityIdParser; use Wikibase\DataModel\Services\Lookup\EntityLookup; @@ -175,11 +175,17 @@ private $readFullEntityIdColumn; /** + * @var int + */ + private $entityUsagePerPageLimit; + + /** * @param EntityChangeFactory $entityChangeFactory * @param EntityIdParser $entityIdParser * @param EntityIdComposer $entityIdComposer * @param EntityNamespaceLookup $entityNamespaceLookup * @param WikibaseServices $wikibaseServices + * @param SettingsArray $settings * @param string|bool $repoWiki The symbolic database name of the repo wiki or false for the * local wiki. * @param string $languageCode @@ -190,6 +196,7 @@ EntityIdComposer $entityIdComposer, EntityNamespaceLookup $entityNamespaceLookup, WikibaseServices $wikibaseServices, + SettingsArray $settings, $repoWiki = false, $languageCode ) { @@ -201,8 +208,7 @@ $this->repoWiki = $repoWiki; $this->languageCode = $languageCode; - // @TODO: Inject - $settings = WikibaseClient::getDefaultInstance()->getSettings(); + // @TODO: split the class so it needs less injection $this->cacheKeyPrefix = $settings->getSetting( 'sharedCacheKeyPrefix' ); $this->cacheType = $settings->getSetting( 'sharedCacheType' ); $this->cacheDuration = $settings->getSetting( 'sharedCacheDuration' ); @@ -210,6 +216,7 @@ $this->writeFullEntityIdColumn = $settings->getSetting( 'writeFullEntityIdColumn' ); $this->disabledUsageAspects = $settings->getSetting( 'disabledUsageAspects' ); $this->readFullEntityIdColumn = $settings->getSetting( 'readFullEntityIdColumn' ); + $this->entityUsagePerPageLimit = $settings->getSetting( 'entityUsagePerPageLimit' ); } /** @@ -287,7 +294,12 @@ public function getUsageTracker() { if ( $this->usageTracker === null ) { $connectionManager = $this->getLocalConnectionManager(); - $this->usageTracker = new SqlUsageTracker( $this->entityIdParser, $connectionManager, $this->disabledUsageAspects ); + $this->usageTracker = new SqlUsageTracker( + $this->entityIdParser, + $connectionManager, + $this->disabledUsageAspects, + $this->entityUsagePerPageLimit + ); } return $this->usageTracker; diff --git a/client/includes/Usage/Sql/SqlUsageTracker.php b/client/includes/Usage/Sql/SqlUsageTracker.php index ffd1525..82fd5dd 100644 --- a/client/includes/Usage/Sql/SqlUsageTracker.php +++ b/client/includes/Usage/Sql/SqlUsageTracker.php @@ -42,6 +42,13 @@ private $disabledUsageAspects; /** + * The limit to issue a warning when entity usage per page hit that limit + * + * @var int + */ + private $entityUsagePerPageLimit; + + /** * @param EntityIdParser $idParser * @param SessionConsistentConnectionManager $connectionManager * @param string[] $disabledUsageAspects @@ -49,11 +56,13 @@ public function __construct( EntityIdParser $idParser, SessionConsistentConnectionManager $connectionManager, - array $disabledUsageAspects + array $disabledUsageAspects, + $entityUsagePerPageLimit ) { $this->idParser = $idParser; $this->connectionManager = $connectionManager; $this->disabledUsageAspects = $disabledUsageAspects; + $this->entityUsagePerPageLimit = $entityUsagePerPageLimit; } /** @@ -134,6 +143,12 @@ throw new InvalidArgumentException( '$pageId must be an int.' ); } + if ( count( $usages ) > $this->entityUsagePerPageLimit ) { + wfLogWarning( + 'Number of usages in page id ' . $pageId . ' is too high: ' . count( $usages ) + ); + } + $usages = $this->handleBlacklistedUsages( $usages ); if ( empty( $usages ) ) { return; diff --git a/client/includes/WikibaseClient.php b/client/includes/WikibaseClient.php index a733b76..e28047f 100644 --- a/client/includes/WikibaseClient.php +++ b/client/includes/WikibaseClient.php @@ -538,6 +538,7 @@ $this->getEntityIdComposer(), $this->getEntityNamespaceLookup(), $this->getWikibaseServices(), + $this->getSettings(), $this->getRepositoryDefinitions()->getDatabaseNames()[''], $this->getContentLanguage()->getCode() ); diff --git a/client/tests/phpunit/includes/Store/Sql/DirectSqlStoreTest.php b/client/tests/phpunit/includes/Store/Sql/DirectSqlStoreTest.php index bf1bad7..01aaec0 100644 --- a/client/tests/phpunit/includes/Store/Sql/DirectSqlStoreTest.php +++ b/client/tests/phpunit/includes/Store/Sql/DirectSqlStoreTest.php @@ -43,7 +43,7 @@ ->disableOriginalConstructor() ->getMock(); - $client = WikibaseClient::getDefaultInstance(); + $wikibaseClient = WikibaseClient::getDefaultInstance(); $wikibaseServices = $this->getMock( WikibaseServices::class ); @@ -60,6 +60,7 @@ new EntityIdComposer( [] ), new EntityNamespaceLookup( [] ), $wikibaseServices, + $wikibaseClient->getSettings(), wfWikiID(), 'en' ); diff --git a/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php b/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php index 15d0c4f..969f92e 100644 --- a/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php +++ b/client/tests/phpunit/includes/Usage/Sql/SqlUsageTrackerTest.php @@ -49,7 +49,8 @@ $this->sqlUsageTracker = new SqlUsageTracker( new ItemIdParser(), new SessionConsistentConnectionManager( wfGetLB() ), - [] + [], + 100 ); $this->trackerTester = new UsageTrackerContractTester( $this->sqlUsageTracker, [ $this, 'getUsages' ] ); @@ -90,7 +91,9 @@ $sqlUsageTracker = new SqlUsageTracker( new ItemIdParser(), new SessionConsistentConnectionManager( wfGetLB() ), - [ EntityUsage::STATEMENT_USAGE, EntityUsage::DESCRIPTION_USAGE => EntityUsage::OTHER_USAGE ] + [ EntityUsage::STATEMENT_USAGE, EntityUsage::DESCRIPTION_USAGE => + EntityUsage::OTHER_USAGE ], + 100 ); $sqlUsageTracker->addUsedEntities( 23, $usages ); @@ -118,7 +121,8 @@ $sqlUsageTracker = new SqlUsageTracker( new ItemIdParser(), new SessionConsistentConnectionManager( wfGetLB() ), - [] + [], + 100 ); // Make sure the blacklisted entries are actually removed. $sqlUsageTracker->addUsedEntities( 23, $usages ); @@ -126,7 +130,8 @@ $sqlUsageTrackerWithBlacklist = new SqlUsageTracker( new ItemIdParser(), new SessionConsistentConnectionManager( wfGetLB() ), - [ EntityUsage::STATEMENT_USAGE ] + [ EntityUsage::STATEMENT_USAGE ], + 100 ); $sqlUsageTrackerWithBlacklist->replaceUsedEntities( 23, $usages ); diff --git a/docs/options.wiki b/docs/options.wiki index 929f20c..e5376ed 100644 --- a/docs/options.wiki +++ b/docs/options.wiki @@ -113,6 +113,7 @@ ;otherProjectsLinks: Site global ID list of sites which should be linked in the other projects sidebar section. Empty value will suppress this section. ;propertyOrderUrl: URL to use for retrieving the property order used for sorting properties by property ID. Will be ignored if set to null. ;disabledAccessEntityTypes: List of entity types that access to them in the client should be disabled. +;entityUsagePerPageLimit: If a page in client uses too many aspects and entities, Wikibase issues a warning. This setting determines value of that threshold. The default is 100. === Expert Settings === -- To view, visit https://gerrit.wikimedia.org/r/404973 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic413621d94e19126f63e35f4660d5ed63e927076 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits