From: Aaron Schulz Date: Wed, 21 Aug 2013 20:20:40 +0000 (-0700) Subject: Move slow deletion purges out of complex DB transactions X-Git-Tag: 1.31.0-rc.0~18905^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=c312218534e7d4065a2b474b084f6c5727275707;p=lhc%2Fweb%2Fwiklou.git Move slow deletion purges out of complex DB transactions * This should help reduce deletion related deadlock errors Change-Id: Ie7cafbf87ab0c71cc6c4c4fe1e53af364974a745 --- diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 678a6ad27a..39ef62c6e3 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1527,7 +1527,6 @@ class LocalFile extends File { * @return FileRepoStatus object. */ function delete( $reason, $suppress = false ) { - global $wgUseSquid; if ( $this->getRepo()->getReadOnlyReason() !== false ) { return $this->readOnlyFatalStatus(); } @@ -1545,19 +1544,28 @@ class LocalFile extends File { DeferredUpdates::addUpdate( SiteStatsUpdate::factory( array( 'images' => -1 ) ) ); } - $this->purgeEverything(); - foreach ( $archiveNames as $archiveName ) { - $this->purgeOldThumbnails( $archiveName ); - } + // 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. + $file = $this; + $this->getRepo()->getMasterDB()->onTransactionIdle( + function() use ( $file, $archiveNames ) { + global $wgUseSquid; - if ( $wgUseSquid ) { - // Purge the squid - $purgeUrls = array(); - foreach ($archiveNames as $archiveName ) { - $purgeUrls[] = $this->getArchiveUrl( $archiveName ); + $file->purgeEverything(); + foreach ( $archiveNames as $archiveName ) { + $file->purgeOldThumbnails( $archiveName ); + } + + if ( $wgUseSquid ) { + // Purge the squid + $purgeUrls = array(); + foreach ( $archiveNames as $archiveName ) { + $purgeUrls[] = $file->getArchiveUrl( $archiveName ); + } + SquidUpdate::purge( $purgeUrls ); + } } - SquidUpdate::purge( $purgeUrls ); - } + ); return $status; }