The config class now makes less database reads.
This commit is contained in:
parent
045e94ccf3
commit
0548099f6c
29 changed files with 153 additions and 107 deletions
|
@ -22,6 +22,8 @@ use dbm;
|
|||
*/
|
||||
class Config {
|
||||
|
||||
private static $cache;
|
||||
|
||||
/**
|
||||
* @brief Loads all configuration values of family into a cached storage.
|
||||
*
|
||||
|
@ -32,10 +34,17 @@ class Config {
|
|||
* The category of the configuration value
|
||||
* @return void
|
||||
*/
|
||||
public static function load($family) {
|
||||
public static function load($family = "config") {
|
||||
|
||||
// We don't preload "system" anymore.
|
||||
// This reduces the number of database reads a lot.
|
||||
if ($family == 'system') {
|
||||
return;
|
||||
}
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$r = q("SELECT `v`, `k` FROM `config` WHERE `cat` = '%s' ORDER BY `cat`, `k`, `id`", dbesc($family));
|
||||
$r = q("SELECT `v`, `k` FROM `config` WHERE `cat` = '%s'", dbesc($family));
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
|
@ -43,11 +52,9 @@ class Config {
|
|||
$a->config[$k] = $rr['v'];
|
||||
} else {
|
||||
$a->config[$family][$k] = $rr['v'];
|
||||
self::$cache[$family][$k] = $rr['v'];
|
||||
}
|
||||
}
|
||||
} else if ($family != 'config') {
|
||||
// Negative caching
|
||||
$a->config[$family] = "!<unset>!";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,34 +85,38 @@ class Config {
|
|||
$a = get_app();
|
||||
|
||||
if (!$refresh) {
|
||||
// Looking if the whole family isn't set
|
||||
if (isset($a->config[$family])) {
|
||||
if ($a->config[$family] === '!<unset>!') {
|
||||
return $default_value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($a->config[$family][$key])) {
|
||||
if ($a->config[$family][$key] === '!<unset>!') {
|
||||
// Do we have the cached value? Then return it
|
||||
if (isset(self::$cache[$family][$key])) {
|
||||
if (self::$cache[$family][$key] == '!<unset>!') {
|
||||
return $default_value;
|
||||
} else {
|
||||
return self::$cache[$family][$key];
|
||||
}
|
||||
return $a->config[$family][$key];
|
||||
}
|
||||
}
|
||||
|
||||
$ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s' ORDER BY `id` DESC LIMIT 1",
|
||||
$ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s'",
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
if (count($ret)) {
|
||||
if (dbm::is_result($ret)) {
|
||||
// manage array value
|
||||
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']);
|
||||
$a->config[$family][$key] = $val;
|
||||
|
||||
// Assign the value from the database to the cache
|
||||
self::$cache[$family][$key] = $val;
|
||||
return $val;
|
||||
} else {
|
||||
$a->config[$family][$key] = '!<unset>!';
|
||||
} elseif (isset($a->config[$family][$key])) {
|
||||
|
||||
// Assign the value (mostly) from the .htconfig.php to the cache
|
||||
self::$cache[$family][$key] = $a->config[$family][$key];
|
||||
|
||||
return $a->config[$family][$key];
|
||||
}
|
||||
|
||||
self::$cache[$family][$key] = '!<unset>!';
|
||||
|
||||
return $default_value;
|
||||
}
|
||||
|
||||
|
@ -134,7 +145,14 @@ class Config {
|
|||
return true;
|
||||
}
|
||||
|
||||
$a->config[$family][$key] = $value;
|
||||
if ($family === 'config') {
|
||||
$a->config[$key] = $value;
|
||||
} elseif ($family != 'system') {
|
||||
$a->config[$family][$key] = $value;
|
||||
}
|
||||
|
||||
// Assign the just added value to the cache
|
||||
self::$cache[$family][$key] = $value;
|
||||
|
||||
// manage array value
|
||||
$dbvalue = (is_array($value) ? serialize($value) : $value);
|
||||
|
@ -174,9 +192,8 @@ class Config {
|
|||
*/
|
||||
public static function delete($family, $key) {
|
||||
|
||||
$a = get_app();
|
||||
if (x($a->config[$family],$key)) {
|
||||
unset($a->config[$family][$key]);
|
||||
if (isset(self::$cache[$family][$key])) {
|
||||
unset(self::$cache[$family][$key]);
|
||||
}
|
||||
$ret = q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s'",
|
||||
dbesc($family),
|
||||
|
@ -185,5 +202,4 @@ class Config {
|
|||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php /** @file */
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once('boot.php');
|
||||
|
||||
// Everything we need to boot standalone 'background' processes
|
||||
|
@ -8,21 +10,20 @@ function cli_startup() {
|
|||
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)) {
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/session.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
*
|
||||
* This script is started from mod/item.php to save some time when doing a post.
|
||||
*/
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/threads.php");
|
||||
|
||||
|
@ -21,8 +24,7 @@ function create_shadowentry_run($argv, $argc) {
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
if ($argc != 2) {
|
||||
return;
|
||||
|
|
|
@ -10,6 +10,8 @@ if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
|
|||
chdir($directory);
|
||||
}
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/photos.php");
|
||||
require_once("include/user.php");
|
||||
|
@ -38,8 +40,7 @@ function cron_run(&$argv, &$argc){
|
|||
require_once('mod/nodeinfo.php');
|
||||
require_once('include/post_update.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
require_once("boot.php");
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function cronhooks_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
@ -20,8 +21,7 @@ function cronhooks_run(&$argv, &$argc){
|
|||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
|
||||
$directory = dirname($_SERVER["argv"][0]);
|
||||
|
||||
|
@ -33,8 +35,7 @@ function cronjobs_run(&$argv, &$argc){
|
|||
require_once('include/post_update.php');
|
||||
require_once('mod/nodeinfo.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@ function dbclean_run(&$argv, &$argc) {
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
Config::load('config');
|
||||
Config::load('system');
|
||||
Config::load();
|
||||
|
||||
if (!Config::get('system', 'dbclean', false)) {
|
||||
return;
|
||||
|
|
|
@ -495,7 +495,7 @@ function db_definition($charset) {
|
|||
$database["addon"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
"name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"name" => array("type" => "varchar(190)", "not null" => "1", "default" => ""),
|
||||
"version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"installed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
|
||||
"hidden" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
|
||||
|
@ -504,6 +504,7 @@ function db_definition($charset) {
|
|||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
"name" => array("UNIQUE", "name"),
|
||||
)
|
||||
);
|
||||
$database["attach"] = array(
|
||||
|
@ -922,7 +923,7 @@ function db_definition($charset) {
|
|||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
"hook_file_function" => array("hook(30)","file(60)","function(30)"),
|
||||
"hook_file_function" => array("UNIQUE", "hook(50)","file(80)","function(60)"),
|
||||
)
|
||||
);
|
||||
$database["intro"] = array(
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function dbupdate_run(&$argv, &$argc) {
|
||||
|
@ -16,8 +18,7 @@ function dbupdate_run(&$argv, &$argc) {
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
update_db($a);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/html2plain.php');
|
||||
|
@ -27,8 +30,7 @@ function delivery_run(&$argv, &$argc){
|
|||
require_once('include/bbcode.php');
|
||||
require_once('include/email.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
load_hooks();
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
require_once("boot.php");
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
function directory_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
|
@ -15,15 +17,11 @@ function directory_run(&$argv, &$argc){
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
Config::load();
|
||||
|
||||
if($argc != 2)
|
||||
return;
|
||||
|
||||
load_config('system');
|
||||
|
||||
load_hooks();
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/socgraph.php");
|
||||
|
||||
|
||||
function discover_poco_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
|
@ -21,8 +22,7 @@ function discover_poco_run(&$argv, &$argc){
|
|||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function expire_run(&$argv, &$argc){
|
||||
|
@ -10,19 +12,18 @@ function expire_run(&$argv, &$argc){
|
|||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/items.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once('include/Scrape.php');
|
||||
require_once('include/socgraph.php');
|
||||
|
@ -21,8 +23,7 @@ function gprobe_run(&$argv, &$argc){
|
|||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/html2plain.php');
|
||||
|
@ -59,8 +62,8 @@ function notifier_run(&$argv, &$argc){
|
|||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/email.php');
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
Config::load();
|
||||
|
||||
load_hooks();
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/follow.php");
|
||||
|
||||
|
@ -32,8 +34,7 @@ function onepoll_run(&$argv, &$argc){
|
|||
require_once('include/socgraph.php');
|
||||
require_once('include/queue_fn.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -72,8 +72,7 @@ function pubsubpublish_run(&$argv, &$argc){
|
|||
|
||||
require_once('include/items.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/dfrn.php');
|
||||
|
@ -23,8 +26,7 @@ function queue_run(&$argv, &$argc){
|
|||
require_once('include/bbcode.php');
|
||||
require_once('include/socgraph.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
* @file include/remove_contact.php
|
||||
* @brief Removes orphaned data from deleted contacts
|
||||
*/
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function remove_contact_run($argv, $argc) {
|
||||
|
@ -19,8 +22,7 @@ function remove_contact_run($argv, $argc) {
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
if ($argc != 2) {
|
||||
return;
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/threads.php");
|
||||
|
||||
|
@ -14,8 +17,7 @@ if(is_null($db)) {
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
update_shadow_copy();
|
||||
killme();
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
* @file include/spool_post.php
|
||||
* @brief Posts items that wer spooled because they couldn't be posted.
|
||||
*/
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/items.php");
|
||||
|
||||
|
@ -20,8 +23,7 @@ function spool_post_run($argv, $argc) {
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
$path = get_spoolpath();
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/tags.php");
|
||||
|
||||
|
@ -14,8 +17,7 @@ if(is_null($db)) {
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
update_items();
|
||||
killme();
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/threads.php");
|
||||
|
||||
|
@ -14,8 +17,7 @@ if(is_null($db)) {
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
update_threads();
|
||||
update_threads_mention();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function update_gcontact_run(&$argv, &$argc){
|
||||
|
@ -19,8 +21,7 @@ function update_gcontact_run(&$argv, &$argc){
|
|||
require_once('include/Scrape.php');
|
||||
require_once("include/socgraph.php");
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue