From 77272ea52df92a0bc5fcbaacc1d166dc6eb33811 Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <roeland@famdouma.nl>
Date: Thu, 13 Oct 2016 13:13:39 +0200
Subject: [PATCH] Use cache to determine if value need to be updated

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
---
 lib/private/AllConfig.php | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php
index 52d77bf3f52..af26d30d8e9 100644
--- a/lib/private/AllConfig.php
+++ b/lib/private/AllConfig.php
@@ -215,6 +215,25 @@ class AllConfig implements \OCP\IConfig {
 		// TODO - FIXME
 		$this->fixDIInit();
 
+		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;
+			} else {
+				$qb = $this->connection->getQueryBuilder();
+				$qb->update('preferences')
+					->set('configvalue', $qb->createNamedParameter($value))
+					->where($qb->expr()->eq('userid', $qb->createNamedParameter($userId)))
+					->andWhere($qb->expr()->eq('appid', $qb->createNamedParameter($appName)))
+					->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($key)));
+				$qb->execute();
+
+				$this->userCache[$userId][$appName][$key] = $value;
+				return;
+			}
+		}
+
 		$preconditionArray = [];
 		if (isset($preCondition)) {
 			$preconditionArray = [
-- 
GitLab