Skip to content

Commit

Permalink
MDL-67020 Cache: Release locks in cache_application::get_many()
Browse files Browse the repository at this point in the history
  • Loading branch information
marxjohnson committed Oct 19, 2022
1 parent 9e7d9a0 commit c06fc06
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cache/classes/loaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -1809,10 +1809,11 @@ protected function get_implementation($key, int $requiredversion, int $strictnes
* @throws coding_exception
*/
public function get_many(array $keys, $strictness = IGNORE_MISSING) {
$locks = [];
if ($this->requirelockingread) {
foreach ($keys as $id => $key) {
$lock =$this->acquire_lock($key);
if (!$lock) {
$locks[$key] = $this->acquire_lock($key);
if (!$locks[$key]) {
if ($strictness === MUST_EXIST) {
throw new coding_exception('Could not acquire read locks for all of the items being requested.');
} else {
Expand All @@ -1823,7 +1824,13 @@ public function get_many(array $keys, $strictness = IGNORE_MISSING) {

}
}
return parent::get_many($keys, $strictness);
$result = parent::get_many($keys, $strictness);
if ($this->requirelockingread) {
foreach ($locks as $key => $lock) {
$this->release_lock($key);
}
}
return $result;
}

/**
Expand Down

0 comments on commit c06fc06

Please sign in to comment.