mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #8809 from owncloud/appconfig-caching
Improve caching in AppConfig
This commit is contained in:
commit
e4c3ff03d6
1 changed files with 29 additions and 19 deletions
|
|
@ -51,6 +51,11 @@ class AppConfig implements \OCP\IAppConfig {
|
|||
|
||||
private $appsLoaded = array();
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $apps = null;
|
||||
|
||||
/**
|
||||
* @param \OC\DB\Connection $conn
|
||||
*/
|
||||
|
|
@ -90,12 +95,16 @@ class AppConfig implements \OCP\IAppConfig {
|
|||
|
||||
/**
|
||||
* Get all apps using the config
|
||||
*
|
||||
* @return array an array of app ids
|
||||
*
|
||||
* This function returns a list of all apps that have at least one
|
||||
* entry in the appconfig table.
|
||||
*/
|
||||
public function getApps() {
|
||||
if (is_array($this->apps)) {
|
||||
return $this->apps;
|
||||
}
|
||||
$query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`';
|
||||
$result = $this->conn->executeQuery($query);
|
||||
|
||||
|
|
@ -103,11 +112,13 @@ class AppConfig implements \OCP\IAppConfig {
|
|||
while ($appid = $result->fetchColumn()) {
|
||||
$apps[] = $appid;
|
||||
}
|
||||
$this->apps = $apps;
|
||||
return $apps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the available keys for an app
|
||||
*
|
||||
* @param string $app the app we are looking for
|
||||
* @return array an array of key names
|
||||
*
|
||||
|
|
@ -123,6 +134,7 @@ class AppConfig implements \OCP\IAppConfig {
|
|||
|
||||
/**
|
||||
* Gets the config value
|
||||
*
|
||||
* @param string $app app
|
||||
* @param string $key key
|
||||
* @param string $default = null, default value if the key does not exist
|
||||
|
|
@ -142,6 +154,7 @@ class AppConfig implements \OCP\IAppConfig {
|
|||
|
||||
/**
|
||||
* check if a key is set in the appconfig
|
||||
*
|
||||
* @param string $app
|
||||
* @param string $key
|
||||
* @return bool
|
||||
|
|
@ -153,6 +166,7 @@ class AppConfig implements \OCP\IAppConfig {
|
|||
|
||||
/**
|
||||
* sets a value in the appconfig
|
||||
*
|
||||
* @param string $app app
|
||||
* @param string $key key
|
||||
* @param string $value value
|
||||
|
|
@ -181,11 +195,15 @@ class AppConfig implements \OCP\IAppConfig {
|
|||
if (!isset($this->cache[$app])) {
|
||||
$this->cache[$app] = array();
|
||||
}
|
||||
if (is_array($this->apps) and array_search($app, $this->apps) === false) {
|
||||
$this->apps[$app] = $app;
|
||||
}
|
||||
$this->cache[$app][$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a key
|
||||
*
|
||||
* @param string $app app
|
||||
* @param string $key key
|
||||
* @return boolean|null
|
||||
|
|
@ -203,6 +221,7 @@ class AppConfig implements \OCP\IAppConfig {
|
|||
|
||||
/**
|
||||
* Remove app from appconfig
|
||||
*
|
||||
* @param string $app app
|
||||
* @return boolean|null
|
||||
*
|
||||
|
|
@ -214,6 +233,7 @@ class AppConfig implements \OCP\IAppConfig {
|
|||
);
|
||||
$this->conn->delete('*PREFIX*appconfig', $where);
|
||||
unset($this->cache[$app]);
|
||||
unset($this->apps[$app]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -228,28 +248,18 @@ class AppConfig implements \OCP\IAppConfig {
|
|||
return false;
|
||||
}
|
||||
|
||||
$fields = '`configvalue`';
|
||||
$where = 'WHERE';
|
||||
$params = array();
|
||||
if ($app !== false) {
|
||||
$fields .= ', `configkey`';
|
||||
$where .= ' `appid` = ?';
|
||||
$params[] = $app;
|
||||
$key = 'configkey';
|
||||
return $this->getAppValues($app);
|
||||
} else {
|
||||
$fields .= ', `appid`';
|
||||
$where .= ' `configkey` = ?';
|
||||
$params[] = $key;
|
||||
$key = 'appid';
|
||||
}
|
||||
$query = 'SELECT ' . $fields . ' FROM `*PREFIX*appconfig` ' . $where;
|
||||
$result = $this->conn->executeQuery($query, $params);
|
||||
$query = 'SELECT `configvalue`, `appid` FROM `*PREFIX*appconfig` WHERE `configkey` = ?';
|
||||
$result = $this->conn->executeQuery($query, array($key));
|
||||
|
||||
$values = array();
|
||||
while ($row = $result->fetch((\PDO::FETCH_ASSOC))) {
|
||||
$values[$row[$key]] = $row['configvalue'];
|
||||
}
|
||||
$values = array();
|
||||
while ($row = $result->fetch((\PDO::FETCH_ASSOC))) {
|
||||
$values[$row['appid']] = $row['configvalue'];
|
||||
}
|
||||
|
||||
return $values;
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue