jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/391187 )
Change subject: Refactor ItemNotabilityFilter to avoid ItemId::newFromNumber
......................................................................
Refactor ItemNotabilityFilter to avoid ItemId::newFromNumber
Instead it uses ItemId::getNumericId() now, which is well defined via
an interface. The remaining technical debt is what
SiteLinkLookup::getLinks returns. I hope this is much more local now
and much easier to change in the future. This is tracked in T114904.
Bug: T151578
Change-Id: Icbb382fec2dfddf967c3cb38d71d77286e108c87
---
M includes/ItemNotabilityFilter.php
1 file changed, 14 insertions(+), 25 deletions(-)
Approvals:
Addshore: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/ItemNotabilityFilter.php
b/includes/ItemNotabilityFilter.php
index 2fb0e14..548665d 100644
--- a/includes/ItemNotabilityFilter.php
+++ b/includes/ItemNotabilityFilter.php
@@ -77,7 +77,7 @@
return [];
}
- $numericItemIds = [];
+ $byNumericId = [];
$pagePropsByItem = $this->getPagePropsByItem( $itemIds );
@@ -91,22 +91,20 @@
$pageProps['wb-claims'] >= self::MIN_STATEMENTS
&&
$pageProps['wb-sitelinks'] >=
self::MIN_SITELINKS
) {
- $numericItemIds[] = $itemId->getNumericId();
+ $byNumericId[$itemId->getNumericId()] = $itemId;
}
}
- return $this->getItemsWithoutArticle( $numericItemIds );
+ return $this->getItemsWithoutArticle( $byNumericId );
}
/**
- * Get number of statements and claims for a list of ItemIds
- *
* @param ItemId[] $itemIds
*
* @return int[][] Map of page_title => propname => numeric value
*/
private function getPagePropsByItem( array $itemIds ) {
- $statementsClaimsCount = [];
+ $values = [];
$dbr = $this->connectionManager->getReadConnection();
@@ -115,10 +113,10 @@
$this->connectionManager->releaseConnection( $dbr );
foreach ( $res as $row ) {
-
$statementsClaimsCount[$row->page_title][$row->pp_propname] = intval(
$row->pp_value ?: 0 );
+ $values[$row->page_title][$row->pp_propname] = intval(
$row->pp_value ?: 0 );
}
- return $statementsClaimsCount;
+ return $values;
}
/**
@@ -155,32 +153,23 @@
}
/**
- * @param int[] $numericItemIds
+ * @param ItemId[] $itemIds expected to be indexed by numeric item ID
*
* @return ItemId[]
*/
- private function getItemsWithoutArticle( array $numericItemIds ) {
- if ( $numericItemIds === [] ) {
+ private function getItemsWithoutArticle( array $itemIds ) {
+ if ( $itemIds === [] ) {
return [];
}
- $itemIds = [];
- $links = $this->siteLinkLookup->getLinks( $numericItemIds, [
$this->siteGlobalId ] );
+ $links = $this->siteLinkLookup->getLinks( array_keys( $itemIds
), [ $this->siteGlobalId ] );
- if ( !empty( $links ) ) {
- foreach ( $links as $link ) {
- $key = array_search( $link[2], $numericItemIds
);
- if ( $key !== false ) {
- unset( $numericItemIds[$key] );
- }
- }
+ foreach ( $links as $link ) {
+ list( , , $numericId ) = $link;
+ unset( $itemIds[$numericId] );
}
- foreach ( $numericItemIds as $itemId ) {
- $itemIds[] = ItemId::newFromNumber( $itemId );
- }
-
- return $itemIds;
+ return array_values( $itemIds );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/391187
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icbb382fec2dfddf967c3cb38d71d77286e108c87
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticlePlaceholder
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Lucie Kaffee <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits