diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:31:33 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:31:33 -0400 |
commit | 150f94f051128f367bc89f6b7e5f57eb2a69fc62 (patch) | |
tree | 181f454813b310ee97385058c6c6f2e3f34d5fd8 /includes/api/ApiStashEdit.php | |
parent | 7e85254903c7c0cb49e381f16b18441ea7b058cc (diff) | |
parent | 80f7dc77d430774192b929d780f96260066df2ee (diff) |
Merge commit '80f7dc'
# Conflicts:
# extensions/ArchInterWiki.sql
Diffstat (limited to 'includes/api/ApiStashEdit.php')
-rw-r--r-- | includes/api/ApiStashEdit.php | 63 |
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'." ); |