From ffe345f7deed6b83b6cd57bcd269a2fcf76acc4a Mon Sep 17 00:00:00 2001 From: Stefan Lorenz Date: Fri, 8 Mar 2019 14:18:44 +0100 Subject: [PATCH] only write lock when its content has changed --- src/Lock.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Lock.php b/src/Lock.php index f7e2993b7..56ba6f0e2 100644 --- a/src/Lock.php +++ b/src/Lock.php @@ -20,6 +20,7 @@ class Lock { private $json; private $lock = []; + private $changed = false; public function __construct($lockFile) { @@ -38,6 +39,7 @@ public function add($name, $data) { $current = $this->lock[$name] ?? []; $this->lock[$name] = array_merge($current, $data); + $this->changed = true; } public function get($name) @@ -48,15 +50,21 @@ public function get($name) public function set($name, $data) { $this->lock[$name] = $data; + $this->changed = true; } public function remove($name) { unset($this->lock[$name]); + $this->changed = true; } public function write() { + if (!$this->changed) { + return; + } + if ($this->lock) { ksort($this->lock); $this->json->write($this->lock);