diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-02-07 14:03:39 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-02-07 14:03:39 +0100 |
commit | cd3ef0bb9d6585dcc07e7ca62285032245283106 (patch) | |
tree | 462f34b473a4b1f9e026ca42223584086ed4883c /lib | |
parent | b537d90e58913be203fd96f31b624559be00abeb (diff) | |
download | nextcloud-server-cd3ef0bb9d6585dcc07e7ca62285032245283106.tar.gz nextcloud-server-cd3ef0bb9d6585dcc07e7ca62285032245283106.zip |
Add caching to appconfig
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/appconfig.php | 61 | ||||
-rw-r--r-- | lib/private/db/statementwrapper.php | 3 |
2 files changed, 48 insertions, 16 deletions
diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php index ff47f08d485..71aa8307316 100644 --- a/lib/private/appconfig.php +++ b/lib/private/appconfig.php @@ -47,6 +47,10 @@ class AppConfig implements \OCP\IAppConfig { */ protected $conn; + private $cache = array(); + + private $appsLoaded = array(); + /** * @param \OC\DB\Connection $conn */ @@ -55,6 +59,32 @@ class AppConfig implements \OCP\IAppConfig { } /** + * @param string $app + * @return string[] + */ + private function getAppCache($app) { + if (!isset($this->cache[$app])) { + $this->cache[$app] = array(); + } + return $this->cache[$app]; + } + + private function getAppValues($app) { + $appCache = $this->getAppCache($app); + if (array_search($app, $this->appsLoaded) === false) { + $query = 'SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`' + . ' WHERE `appid` = ?'; + $result = $this->conn->executeQuery($query, array($app)); + while ($row = $result->fetch()) { + $appCache[$row['configkey']] = $row['configvalue']; + } + $this->appsLoaded[] = $app; + } + $this->cache[$app] = $appCache; + return $appCache; + } + + /** * @brief Get all apps using the config * @return array with app ids * @@ -81,15 +111,8 @@ class AppConfig implements \OCP\IAppConfig { * not returned. */ public function getKeys($app) { - $query = 'SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'; - $result = $this->conn->executeQuery($query, array($app)); - - $keys = array(); - while ($key = $result->fetchColumn()) { - $keys[] = $key; - } - - return $keys; + $values = $this->getAppValues($app); + return array_keys($values); } /** @@ -103,11 +126,9 @@ class AppConfig implements \OCP\IAppConfig { * not exist the default value will be returned */ public function getValue($app, $key, $default = null) { - $query = 'SELECT `configvalue` FROM `*PREFIX*appconfig`' - . ' WHERE `appid` = ? AND `configkey` = ?'; - $row = $this->conn->fetchAssoc($query, array($app, $key)); - if ($row) { - return $row['configvalue']; + $values = $this->getAppValues($app); + if (isset($values[$key])) { + return $values[$key]; } else { return $default; } @@ -120,8 +141,8 @@ class AppConfig implements \OCP\IAppConfig { * @return bool */ public function hasKey($app, $key) { - $exists = $this->getKeys($app); - return in_array($key, $exists); + $values = $this->getAppValues($app); + return isset($values[$key]); } /** @@ -151,6 +172,10 @@ class AppConfig implements \OCP\IAppConfig { ); $this->conn->update('*PREFIX*appconfig', $data, $where); } + if (!isset($this->cache[$app])) { + $this->cache[$app] = array(); + } + $this->cache[$app][$key] = $value; } /** @@ -167,6 +192,9 @@ class AppConfig implements \OCP\IAppConfig { 'configkey' => $key, ); $this->conn->delete('*PREFIX*appconfig', $where); + if (isset($this->cache[$app]) and isset($this->cache[$app][$key])) { + unset($this->cache[$app][$key]); + } } /** @@ -181,6 +209,7 @@ class AppConfig implements \OCP\IAppConfig { 'appid' => $app, ); $this->conn->delete('*PREFIX*appconfig', $where); + unset($this->cache[$app]); } /** diff --git a/lib/private/db/statementwrapper.php b/lib/private/db/statementwrapper.php index 5e89261d936..a71df315e2f 100644 --- a/lib/private/db/statementwrapper.php +++ b/lib/private/db/statementwrapper.php @@ -31,6 +31,9 @@ class OC_DB_StatementWrapper { /** * make execute return the result instead of a bool + * + * @param array $input + * @return \OC_DB_StatementWrapper | int */ public function execute($input=array()) { if(OC_Config::getValue( "log_query", false)) { |