Skip to content

Commit

Permalink
Fixed #3450
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed Mar 7, 2019
1 parent e7b212a commit a5d56c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Fixed a bug where the `positionedBefore` element query param was not including direct ancestors in the results.
- Fixed a bug where HTML in plugin-supplied field instructions was getting encoded. ([#3928](https://github.com/craftcms/cms/issues/3928))
- Fixed a bug where Craft would prompt for a user’s current password when registering a new user, even if they weren’t assigning any groups or permissions to that user
- Fixed a bug where a race condition could make Asset indexing inconsistent. ([#3450](https://github.com/craftcms/cms/issues/3450))

## 3.1.16 - 2019-03-05

Expand Down
9 changes: 9 additions & 0 deletions src/services/AssetIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,22 @@ public function storeIndexList(array $indexList, string $sessionId, int $volumeI
*/
public function processIndexForVolume(string $sessionId, int $volumeId, bool $cacheImages = false)
{
$mutex = Craft::$app->getMutex();
$lockName = 'idx--' . $sessionId;

if (!$mutex->acquire($lockName, 5)) {
throw new Exception('Could not acquire a lock for the indexing sessiong "' . $sessionId . '".');
}

if (($indexEntryModel = $this->getNextIndexEntry($sessionId, $volumeId)) === null) {
return false;
}

// Mark as started.
$this->updateIndexEntry($indexEntryModel->id, ['inProgress' => true]);

$mutex->release($lockName);

try {
$asset = $this->_indexFileByIndexData($indexEntryModel, $cacheImages);
$this->updateIndexEntry($indexEntryModel->id, ['completed' => true, 'inProgress' => false, 'recordId' => $asset->id]);
Expand Down

0 comments on commit a5d56c8

Please sign in to comment.