jenkins-bot has submitted this change and it was merged.

Change subject: Use FileRepo::findFiles() to avoid a bunch of queries
......................................................................


Use FileRepo::findFiles() to avoid a bunch of queries

* Also track the redirect page usages themselves in the table (as is done for 
templatelinks)

Change-Id: I93e07f823d6252b1916be96792a1d973ab9170b2
---
M GlobalUsageHooks.php
1 file changed, 20 insertions(+), 8 deletions(-)

Approvals:
  Anomie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/GlobalUsageHooks.php b/GlobalUsageHooks.php
index 8411181..750168c 100644
--- a/GlobalUsageHooks.php
+++ b/GlobalUsageHooks.php
@@ -17,20 +17,32 @@
        public static function onLinksUpdateComplete( $linksUpdater ) {
                $title = $linksUpdater->getTitle();
 
-               // Create a list of locally existing images
+               // Create a list of locally existing images (DB keys)
                $images = array_keys( $linksUpdater->getImages() );
 
-               //$localFiles = array_keys( 
RepoGroup::singleton()->getLocalRepo()->findFiles( $images ) );
-               // Unrolling findFiles() here because pages with thousands of 
images trigger an OOM
-               // error while building an array with thousands of File objects 
(bug 32598)
                $localFiles = array();
                $repo = RepoGroup::singleton()->getLocalRepo();
-               foreach ( $images as $image ) {
-                       $file = $repo->findFile( $image );
-                       if ( $file ) {
-                               $localFiles[] = $file->getTitle()->getDBkey();
+               if ( defined( 'FileRepo::NAME_AND_TIME_ONLY' ) ) { // MW 1.23
+                       $imagesInfo = $repo->findFiles( $images, 
FileRepo::NAME_AND_TIME_ONLY );
+                       foreach ( $imagesInfo as $dbKey => $info ) {
+                               $localFiles[] = $dbKey;
+                               if ( $dbKey !== $info['title'] ) { // redirect
+                                       $localFiles[] = $info['title'];
+                               }
+                       }
+               } else {
+                       // Unrolling findFiles() here because pages with 
thousands of images trigger an OOM
+                       foreach ( $images as $dbKey ) {
+                               $file = $repo->findFile( $dbKey );
+                               if ( $file ) {
+                                       $localFiles[] = $dbKey;
+                                       if ( $file->getTitle()->getDBkey() !== 
$dbKey ) { // redirect
+                                               $localFiles[] = 
$file->getTitle()->getDBkey();
+                                       }
+                               }
                        }
                }
+               $localFiles = array_values( array_unique( $localFiles ) );
 
                $missingFiles = array_diff( $images, $localFiles );
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I93e07f823d6252b1916be96792a1d973ab9170b2
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/GlobalUsage
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to