Skip to content

Commit

Permalink
Fix Could not get the lock for ID, when creating a site (matomo-org#1…
Browse files Browse the repository at this point in the history
…5401)

* Lock key start

* do not empty key lock

Co-authored-by: Thomas Steur <[email protected]>
  • Loading branch information
2 people authored and jonasgrilleres committed Sep 22, 2020
1 parent d558b36 commit 1deb64b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/Concurrency/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ public function getAllAcquiredLockKeys()

public function execute($id, $callback)
{
if (Common::mb_strlen($id) > self::MAX_KEY_LEN) {
$maxLen = self::MAX_KEY_LEN;
if (!empty($this->lockKeyStart)) {
$maxLen = $maxLen - strlen($this->lockKeyStart);
}
if (Common::mb_strlen($id) > $maxLen) {
// Lock key might be too long for DB column, so we hash it but leave the start of the original as well
// to make it more readable
$md5Len = 32;
$id = Common::mb_substr($id, 0, self::MAX_KEY_LEN - $md5Len - 1) . md5($id);
$id = Common::mb_substr($id, 0, $maxLen - $md5Len - 1) . md5($id);
}

$i = 0;
Expand Down

0 comments on commit 1deb64b

Please sign in to comment.