From 3a030622b56e2c8fa8de639bc5006d30a95c7348 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 9 Dec 2014 13:48:17 -0800 Subject: [PATCH] Various edit stash fixes * Unlock the key at the right point, so checkCache actually sees the result * Turn CRLF to LF just as EditPage does via getText(), this avoids misses * Added a bit more debug logging Change-Id: I5c296325ebee2501e5de59b8090e1ddde8689f17 --- includes/api/ApiStashEdit.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php index 00f68147bf..fd5bd7e9f2 100644 --- a/includes/api/ApiStashEdit.php +++ b/includes/api/ApiStashEdit.php @@ -48,7 +48,8 @@ class ApiStashEdit extends ApiBase { $this->dieUsage( "Unsupported content model/format", 'badmodelformat' ); } - $text = trim( $params['text'] ); // needed so the key SHA1's match + // Trim and fix newlines so the key SHA1's match (see RequestContext::getText()) + $text = rtrim( str_replace( "\r\n", "\n", $params['text'] ) ); $textContent = ContentHandler::makeContent( $text, $title, $params['contentmodel'], $params['contentformat'] ); @@ -109,8 +110,11 @@ class ApiStashEdit extends ApiBase { } elseif ( $wgMemc->lock( $key, 0, 30 ) ) { $contentFormat = $content->getDefaultFormat(); $editInfo = $page->prepareContentForEdit( $content, null, $user, $contentFormat ); - $wgMemc->unlock( $key ); $status = 'error'; // default + $unlocker = new ScopedCallback( function() use ( $key ) { + global $wgMemc; + $wgMemc->unlock( $key ); + } ); } else { $editInfo = false; $status = 'busy'; @@ -195,12 +199,13 @@ class ApiStashEdit extends ApiBase { if ( $wgMemc->lock( $key, 30, 30 ) ) { $editInfo = $wgMemc->get( $key ); $wgMemc->unlock( $key ); - $sec = microtime( true ) - $start; - wfDebugLog( 'StashEdit', "Waited $sec seconds on '$key'." ); } + $sec = microtime( true ) - $start; + wfDebugLog( 'StashEdit', "Waited $sec seconds on '$key'." ); } if ( !is_object( $editInfo ) || !$editInfo->output ) { + wfDebugLog( 'StashEdit', "No cache value for key '$key'." ); return false; } -- 2.20.1