summaryrefslogtreecommitdiff
path: root/includes/api/ApiStashEdit.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiStashEdit.php')
-rw-r--r--includes/api/ApiStashEdit.php63
1 files changed, 41 insertions, 22 deletions
diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php
index c4b717c7..d068e945 100644
--- a/includes/api/ApiStashEdit.php
+++ b/includes/api/ApiStashEdit.php
@@ -276,36 +276,55 @@ class ApiStashEdit extends ApiBase {
}
$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'." );