mirror of
https://github.com/friendica/friendica
synced 2024-11-14 03:42:53 +00:00
Merge pull request #6688 from nupplaphil/preload_adapter_fix
Preload adapter fix
This commit is contained in:
commit
e32ef66f68
6 changed files with 54 additions and 23 deletions
|
@ -34,10 +34,13 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte
|
||||||
$configs = DBA::select('config', ['v', 'k'], ['cat' => $cat]);
|
$configs = DBA::select('config', ['v', 'k'], ['cat' => $cat]);
|
||||||
while ($config = DBA::fetch($configs)) {
|
while ($config = DBA::fetch($configs)) {
|
||||||
$key = $config['k'];
|
$key = $config['k'];
|
||||||
|
$value = $config['v'];
|
||||||
|
|
||||||
$return[$key] = $config['v'];
|
if (isset($value) && $value !== '') {
|
||||||
|
$return[$key] = $value;
|
||||||
$this->in_db[$cat][$key] = true;
|
$this->in_db[$cat][$key] = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
DBA::close($configs);
|
DBA::close($configs);
|
||||||
|
|
||||||
return [$cat => $config];
|
return [$cat => $config];
|
||||||
|
|
|
@ -29,11 +29,13 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
|
||||||
if (DBA::isResult($pconfigs)) {
|
if (DBA::isResult($pconfigs)) {
|
||||||
while ($pconfig = DBA::fetch($pconfigs)) {
|
while ($pconfig = DBA::fetch($pconfigs)) {
|
||||||
$key = $pconfig['k'];
|
$key = $pconfig['k'];
|
||||||
|
$value = $pconfig['v'];
|
||||||
|
|
||||||
$return[$key] = $pconfig['v'];
|
if (isset($value) && $value !== '') {
|
||||||
|
$return[$key] = $value;
|
||||||
$this->in_db[$uid][$cat][$key] = true;
|
$this->in_db[$uid][$cat][$key] = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if ($cat != 'config') {
|
} else if ($cat != 'config') {
|
||||||
// Negative caching
|
// Negative caching
|
||||||
$return = "!<unset>!";
|
$return = "!<unset>!";
|
||||||
|
|
|
@ -32,7 +32,12 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
|
||||||
|
|
||||||
$configs = DBA::select('config', ['cat', 'v', 'k']);
|
$configs = DBA::select('config', ['cat', 'v', 'k']);
|
||||||
while ($config = DBA::fetch($configs)) {
|
while ($config = DBA::fetch($configs)) {
|
||||||
$return[$config['cat']][$config['k']] = $config['v'];
|
$value = $config['v'];
|
||||||
|
if (isset($value) && $value !== '') {
|
||||||
|
$return[$config['cat']][$config['k']] = $value;
|
||||||
|
} else {
|
||||||
|
$return[$config['cat']][$config['k']] = '!<unset>!';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DBA::close($configs);
|
DBA::close($configs);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,10 @@ use Friendica\Database\DBA;
|
||||||
*/
|
*/
|
||||||
class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdapter
|
class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdapter
|
||||||
{
|
{
|
||||||
private $config_loaded = false;
|
/**
|
||||||
|
* @var array true if config for user is loaded
|
||||||
|
*/
|
||||||
|
private $config_loaded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $uid The UID of the current user
|
* @param int $uid The UID of the current user
|
||||||
|
@ -22,6 +25,8 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->config_loaded = [];
|
||||||
|
|
||||||
if (isset($uid)) {
|
if (isset($uid)) {
|
||||||
$this->load($uid, 'config');
|
$this->load($uid, 'config');
|
||||||
}
|
}
|
||||||
|
@ -34,21 +39,26 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
|
||||||
{
|
{
|
||||||
$return = [];
|
$return = [];
|
||||||
|
|
||||||
if ($this->config_loaded) {
|
if (empty($uid)) {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($uid)) {
|
if (!$this->isLoaded($uid, $cat, null)) {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
|
$pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
|
||||||
while ($pconfig = DBA::fetch($pconfigs)) {
|
while ($pconfig = DBA::fetch($pconfigs)) {
|
||||||
$return[$pconfig['cat']][$pconfig['k']] = $pconfig['v'];
|
$value = $pconfig['v'];
|
||||||
|
if (isset($value) && $value !== '') {
|
||||||
|
$return[$pconfig['cat']][$pconfig['k']] = $value;
|
||||||
|
} else {
|
||||||
|
$return[$pconfig['cat']][$pconfig['k']] = '!<unset>!';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DBA::close($pconfigs);
|
DBA::close($pconfigs);
|
||||||
|
|
||||||
$this->config_loaded = true;
|
$this->config_loaded[$uid] = true;
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +72,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
|
||||||
return '!<unset>!';
|
return '!<unset>!';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->config_loaded) {
|
if (!$this->isLoaded($uid, $cat, $key)) {
|
||||||
$this->load($uid, $cat);
|
$this->load($uid, $cat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +97,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->config_loaded) {
|
if (!$this->isLoaded($uid, $cat, $key)) {
|
||||||
$this->load($uid, $cat);
|
$this->load($uid, $cat);
|
||||||
}
|
}
|
||||||
// We store our setting values as strings.
|
// We store our setting values as strings.
|
||||||
|
@ -116,7 +126,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->config_loaded) {
|
if (!$this->isLoaded($uid, $cat, $key)) {
|
||||||
$this->load($uid, $cat);
|
$this->load($uid, $cat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +144,6 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->config_loaded;
|
return isset($this->config_loaded[$uid]) && $this->config_loaded[$uid];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,12 @@ class ConfigCache implements IConfigCache, IPConfigCache
|
||||||
$keys = array_keys($config[$category]);
|
$keys = array_keys($config[$category]);
|
||||||
|
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
if (isset($config[$category][$key])) {
|
$value = $config[$category][$key];
|
||||||
|
if (isset($value) && $value !== '!<unset>!') {
|
||||||
if ($overwrite) {
|
if ($overwrite) {
|
||||||
$this->set($category, $key, $config[$category][$key]);
|
$this->set($category, $key, $value);
|
||||||
} else {
|
} else {
|
||||||
$this->setDefault($category, $key, $config[$category][$key]);
|
$this->setDefault($category, $key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,12 +133,22 @@ class ConfigCache implements IConfigCache, IPConfigCache
|
||||||
*/
|
*/
|
||||||
public function loadP($uid, array $config)
|
public function loadP($uid, array $config)
|
||||||
{
|
{
|
||||||
foreach ($config as $category => $values) {
|
$categories = array_keys($config);
|
||||||
foreach ($values as $key => $value) {
|
|
||||||
|
foreach ($categories as $category) {
|
||||||
|
if (isset($config[$category]) && is_array($config[$category])) {
|
||||||
|
|
||||||
|
$keys = array_keys($config[$category]);
|
||||||
|
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
$value = $config[$category][$key];
|
||||||
|
if (isset($value) && $value !== '!<unset>!') {
|
||||||
$this->setP($uid, $category, $key, $value);
|
$this->setP($uid, $category, $key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
/**
|
/**
|
||||||
* @file view/theme/frio/style.php
|
* @file view/theme/frio/style.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\PConfig;
|
use Friendica\Core\PConfig;
|
||||||
use Friendica\Model\Profile;
|
|
||||||
|
|
||||||
require_once 'view/theme/frio/php/PHPColors/Color.php';
|
require_once 'view/theme/frio/php/PHPColors/Color.php';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue