- if ( $editInfo && $editInfo->output ) {
- $key = self::getStashKey( $title, $content, $user );
+ // Use the master DB for fast blocking locks
+ $dbw = wfGetDB( DB_MASTER );
+ if ( !$dbw->lock( $key, __METHOD__, 1 ) ) {
+ // De-duplicate requests on the same key
+ return self::ERROR_BUSY;
+ }
+ $unlocker = new ScopedCallback( function () use ( $dbw, $key ) {
+ $dbw->unlock( $key, __METHOD__ );
+ } );
+
+ $cutoffTime = time() - self::PRESUME_FRESH_TTL_SEC;
+
+ // Reuse any freshly build matching edit stash cache
+ $editInfo = $cache->get( $key );
+ if ( $editInfo && wfTimestamp( TS_UNIX, $editInfo->timestamp ) >= $cutoffTime ) {
+ $alreadyCached = true;
+ } else {
+ $format = $content->getDefaultFormat();
+ $editInfo = $page->prepareContentForEdit( $content, null, $user, $format, false );
+ $alreadyCached = false;
+ }