From: Aaron Schulz Date: Thu, 17 Oct 2013 18:35:00 +0000 (-0700) Subject: Reduce excess lock contention and chance for failure on rename X-Git-Tag: 1.31.0-rc.0~18471 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=bbadd9b3df186fa83f3183d163335b2ed7e79b66;p=lhc%2Fweb%2Fwiklou.git Reduce excess lock contention and chance for failure on rename * DB locks and transactions were getting held up by sometimes slow purges (10+ seconds) Change-Id: I0eead60e8faf5aee6b2ddf59cfdd928f9c8083ff --- diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 0c34f3e4f7..fe769be28c 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1507,18 +1507,27 @@ class LocalFile extends File { wfDebugLog( 'imagemove', "Finished moving {$this->name}" ); - $this->purgeEverything(); - foreach ( $archiveNames as $archiveName ) { - $this->purgeOldThumbnails( $archiveName ); - } + // Purge the source and target files... + $oldTitleFile = wfLocalFile( $this->title ); + $newTitleFile = wfLocalFile( $target ); + // Hack: the lock()/unlock() pair is nested in a transaction so the locking is not + // tied to BEGIN/COMMIT. To avoid slow purges in the transaction, move them outside. + $this->getRepo()->getMasterDB()->onTransactionIdle( + function() use ( $oldTitleFile, $newTitleFile, $archiveNames ) { + $oldTitleFile->purgeEverything(); + foreach ( $archiveNames as $archiveName ) { + $oldTitleFile->purgeOldThumbnails( $archiveName ); + } + $newTitleFile->purgeEverything(); + } + ); + if ( $status->isOK() ) { // Now switch the object $this->title = $target; // Force regeneration of the name and hashpath unset( $this->name ); unset( $this->hashPath ); - // Purge the new image - $this->purgeEverything(); } return $status;