Reedy has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/244453

Change subject: Fixed edit stash inclusion queries
......................................................................

Fixed edit stash inclusion queries

* These are hit when the stashed edit is several seconds
  old. The old code was not using makeList() correctly.

Bug: T105597
Change-Id: I265307715996c50d819915a55ea34bbc0ed6c5c9
(cherry picked from commit 6ed8416a7010ac62215df461deadcda68d396590)
---
M includes/api/ApiStashEdit.php
1 file changed, 41 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/53/244453/1

diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php
index c4b717c..d068e94 100644
--- a/includes/api/ApiStashEdit.php
+++ b/includes/api/ApiStashEdit.php
@@ -276,36 +276,55 @@
                }
 
                $dbr = wfGetDB( DB_SLAVE );
-               // Check that no templates used in the output changed...
-               $cWhr = array(); // conditions to find changes/creations
-               $dWhr = array(); // conditions to find deletions
+
+               $templates = array(); // conditions to find changes/creations
+               $templateUses = 0; // expected existing templates
                foreach ( $editInfo->output->getTemplateIds() as $ns => $stuff 
) {
                        foreach ( $stuff as $dbkey => $revId ) {
-                               $cWhr[] = array( 'page_namespace' => $ns, 
'page_title' => $dbkey,
-                                       'page_latest != ' . intval( $revId ) );
-                               $dWhr[] = array( 'page_namespace' => $ns, 
'page_title' => $dbkey );
+                               $templates[(string)$ns][$dbkey] = (int)$revId;
+                               ++$templateUses;
                        }
                }
-               $change = $dbr->selectField( 'page', '1', $dbr->makeList( 
$cWhr, LIST_OR ), __METHOD__ );
-               $n = $dbr->selectField( 'page', 'COUNT(*)', $dbr->makeList( 
$dWhr, LIST_OR ), __METHOD__ );
-               if ( $change || $n != count( $dWhr ) ) {
-                       wfDebugLog( 'StashEdit', "Stale cache for key '$key'; 
template changed." );
-                       return false;
+               // Check that no templates used in the output changed...
+               if ( count( $templates ) ) {
+                       $res = $dbr->select(
+                               'page',
+                               array( 'ns' => 'page_namespace', 'dbk' => 
'page_title', 'page_latest' ),
+                               $dbr->makeWhereFrom2d( $templates, 
'page_namespace', 'page_title' ),
+                               __METHOD__
+                       );
+                       $changed = false;
+                       foreach ( $res as $row ) {
+                               $changed = $changed || ( $row->page_latest != 
$templates[$row->ns][$row->dbk] );
+                       }
+
+                       if ( $changed || $res->numRows() != $templateUses ) {
+                               wfDebugLog( 'StashEdit', "Stale cache for key 
'$key'; template changed." );
+                               return false;
+                       }
                }
 
-               // Check that no files used in the output changed...
-               $cWhr = array(); // conditions to find changes/creations
-               $dWhr = array(); // conditions to find deletions
+               $files = array(); // conditions to find changes/creations
                foreach ( $editInfo->output->getFileSearchOptions() as $name => 
$options ) {
-                       $cWhr[] = array( 'img_name' => $dbkey,
-                               'img_sha1 != ' . $dbr->addQuotes( strval( 
$options['sha1'] ) ) );
-                       $dWhr[] = array( 'img_name' => $dbkey );
+                       $files[$name] = (string)$options['sha1'];
                }
-               $change = $dbr->selectField( 'image', '1', $dbr->makeList( 
$cWhr, LIST_OR ), __METHOD__ );
-               $n = $dbr->selectField( 'image', 'COUNT(*)', $dbr->makeList( 
$dWhr, LIST_OR ), __METHOD__ );
-               if ( $change || $n != count( $dWhr ) ) {
-                       wfDebugLog( 'StashEdit', "Stale cache for key '$key'; 
file changed." );
-                       return false;
+               // Check that no files used in the output changed...
+               if ( count( $files ) ) {
+                       $res = $dbr->select(
+                               'image',
+                               array( 'name' => 'img_name', 'img_sha1' ),
+                               array( 'img_name' => array_keys( $files ) ),
+                               __METHOD__
+                       );
+                       $changed = false;
+                       foreach ( $res as $row ) {
+                               $changed = $changed || ( $row->img_sha1 != 
$files[$row->name] );
+                       }
+
+                       if ( $changed || $res->numRows() != count( $files ) ) {
+                               wfDebugLog( 'StashEdit', "Stale cache for key 
'$key'; file changed." );
+                               return false;
+                       }
                }
 
                wfDebugLog( 'StashEdit', "Cache hit for key '$key'." );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I265307715996c50d819915a55ea34bbc0ed6c5c9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_25
Gerrit-Owner: Reedy <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to