Florianschmidtwelzow has uploaded a new change for review.
https://gerrit.wikimedia.org/r/191584
Change subject: Hygiene: Use one query to get all page images
......................................................................
Hygiene: Use one query to get all page images
Bug: T89754
Change-Id: I92a23f5cd90f7c85d02da2525938404130d965e1
---
M includes/stores/ItemImages.php
M includes/stores/WatchlistCollection.php
2 files changed, 24 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather
refs/changes/84/191584/1
diff --git a/includes/stores/ItemImages.php b/includes/stores/ItemImages.php
index 910a7f2..744917a 100644
--- a/includes/stores/ItemImages.php
+++ b/includes/stores/ItemImages.php
@@ -18,8 +18,24 @@
*/
public static function loadImages( array $titles ) {
$images = array();
+ $titleIds = array();
+ // get article ids for page images query
foreach ( $titles as $title ) {
- $images[] = PageImages::getPageImage( $title );
+ $titleIds[] = $title->getArticleId();
+ }
+ // query to get page images for all pages
+ // FIXME: Should probably be in PageImages extension
+ $dbr = wfGetDB( DB_SLAVE );
+ $result = $dbr->select( 'page_props',
+ array( 'pp_value', 'pp_page' ),
+ array( 'pp_page' => $titleIds, 'pp_propname' =>
PageImages::PROP_NAME ),
+ __METHOD__
+ );
+ if ( $result ) {
+ // build results array
+ foreach ( $result as $row ) {
+ $images[$row->pp_page] = wfFindFile(
$row->pp_value );
+ }
}
return $images;
}
diff --git a/includes/stores/WatchlistCollection.php
b/includes/stores/WatchlistCollection.php
index ac40dfe..76d424b 100644
--- a/includes/stores/WatchlistCollection.php
+++ b/includes/stores/WatchlistCollection.php
@@ -47,7 +47,13 @@
// Merge the data into models\CollectionItem
$items = array();
foreach ( $titles as $key=>$title ) {
- $items[] = new models\CollectionItem( $title,
$images[$key], $extracts[$key] );
+ // Check, if this page has a page image
+ if ( isset( $images[$title->getArticleId()] ) ) {
+ $image = $images[$title->getArticleId()];
+ } else {
+ $image = false;
+ }
+ $items[] = new models\CollectionItem( $title, $image,
$extracts[$key] );
}
// Construct the internal models\Collection
--
To view, visit https://gerrit.wikimedia.org/r/191584
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I92a23f5cd90f7c85d02da2525938404130d965e1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits