From 2960b97fc728e9212c63f49cb46fa119853a4e26 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 15 Nov 2016 22:14:27 +0100 Subject: [PATCH 1/2] Don't update value if it is already set to the same value * this PR makes sure to warm up the cache for that user * then the logic within the "if is in cache" code can be used to reduce needed queries * inspired by @andreas-p - https://github.com/nextcloud/server/pull/2128 Signed-off-by: Morris Jobke --- lib/private/AllConfig.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index af26d30d8e9..cd1d5f69ac1 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -215,11 +215,14 @@ class AllConfig implements \OCP\IConfig { // TODO - FIXME $this->fixDIInit(); + // warm up the cache to avoid updating the value if it is already set to this value before + $this->getUserValue($userId, $appName, $key); + if (isset($this->userCache[$userId][$appName][$key])) { if ($this->userCache[$userId][$appName][$key] === (string)$value) { return; } else if ($preCondition !== null && $this->userCache[$userId][$appName][$key] !== (string)$preCondition) { - return; + throw new PreConditionNotMetException(); } else { $qb = $this->connection->getQueryBuilder(); $qb->update('preferences') From 577a8a730f79bf3605f5826fbd1affe16747e3f7 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 16 Nov 2016 18:52:32 +0100 Subject: [PATCH 2/2] Use getvalue to fetch the value Signed-off-by: Roeland Jago Douma --- lib/private/AllConfig.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index cd1d5f69ac1..4e13d70371b 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -215,13 +215,12 @@ class AllConfig implements \OCP\IConfig { // TODO - FIXME $this->fixDIInit(); - // warm up the cache to avoid updating the value if it is already set to this value before - $this->getUserValue($userId, $appName, $key); + $prevValue = $this->getUserValue($userId, $appName, $key, null); - if (isset($this->userCache[$userId][$appName][$key])) { - if ($this->userCache[$userId][$appName][$key] === (string)$value) { + if ($prevValue !== null) { + if ($prevValue === (string)$value) { return; - } else if ($preCondition !== null && $this->userCache[$userId][$appName][$key] !== (string)$preCondition) { + } else if ($preCondition !== null && $prevValue !== (string)$preCondition) { throw new PreConditionNotMetException(); } else { $qb = $this->connection->getQueryBuilder();