Преглед изворни кода

The config class now makes less database reads.

tags/3.5.1
Michael пре 3 година
родитељ
комит
0548099f6c
29 измењених фајлова са 153 додато и 107 уклоњено
  1. +1
    -1
      boot.php
  2. +15
    -14
      database.sql
  3. +40
    -24
      include/Core/Config.php
  4. +9
    -8
      include/cli_startup.php
  5. +4
    -2
      include/create_shadowentry.php
  6. +3
    -2
      include/cron.php
  7. +3
    -3
      include/cronhooks.php
  8. +3
    -2
      include/cronjobs.php
  9. +1
    -2
      include/dbclean.php
  10. +3
    -2
      include/dbstructure.php
  11. +3
    -2
      include/dbupdate.php
  12. +4
    -2
      include/delivery.php
  13. +3
    -5
      include/directory.php
  14. +3
    -3
      include/discover_poco.php
  15. +8
    -7
      include/expire.php
  16. +3
    -2
      include/gprobe.php
  17. +5
    -2
      include/notifier.php
  18. +3
    -2
      include/onepoll.php
  19. +1
    -2
      include/pubsubpublish.php
  20. +4
    -2
      include/queue.php
  21. +4
    -2
      include/remove_contact.php
  22. +4
    -2
      include/shadowupdate.php
  23. +4
    -2
      include/spool_post.php
  24. +4
    -2
      include/tagupdate.php
  25. +4
    -2
      include/threadupdate.php
  26. +3
    -2
      include/update_gcontact.php
  27. +3
    -2
      index.php
  28. +3
    -1
      mod/friendica.php
  29. +5
    -3
      util/maintenance.php

+ 1
- 1
boot.php Прегледај датотеку

@@ -1569,7 +1569,7 @@ function update_db(App $a) {
$stored = intval($build);
$current = intval(DB_UPDATE_VERSION);
if($stored < $current) {
load_config('database');
Config::load('database');

// We're reporting a different version than what is currently installed.
// Run any existing update scripts to bring the database up to current.


+ 15
- 14
database.sql Прегледај датотеку

@@ -9,13 +9,14 @@
--
CREATE TABLE IF NOT EXISTS `addon` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL DEFAULT '',
`name` varchar(190) NOT NULL DEFAULT '',
`version` varchar(255) NOT NULL DEFAULT '',
`installed` tinyint(1) NOT NULL DEFAULT 0,
`hidden` tinyint(1) NOT NULL DEFAULT 0,
`timestamp` bigint(20) NOT NULL DEFAULT 0,
`plugin_admin` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
PRIMARY KEY(`id`),
UNIQUE INDEX `name` (`name`)
) DEFAULT CHARSET=utf8mb4;

--
@@ -32,9 +33,9 @@ CREATE TABLE IF NOT EXISTS `attach` (
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`allow_cid` mediumtext,
`allow_gid` medium_text,
`deny_cid` medium_text,
`deny_gid` medium_text,
`allow_gid` mediumtext,
`deny_cid` mediumtext,
`deny_gid` mediumtext,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8mb4;

@@ -235,10 +236,10 @@ CREATE TABLE IF NOT EXISTS `event` (
`nofinish` tinyint(1) NOT NULL DEFAULT 0,
`adjust` tinyint(1) NOT NULL DEFAULT 1,
`ignore` tinyint(1) unsigned NOT NULL DEFAULT 0,
`allow_cid` medium_text,
`allow_gid` medium_text,
`deny_cid` medium_text,
`deny_gid` medium_text,
`allow_cid` mediumtext,
`allow_gid` mediumtext,
`deny_cid` mediumtext,
`deny_gid` mediumtext,
PRIMARY KEY(`id`),
INDEX `uid_start` (`uid`,`start`)
) DEFAULT CHARSET=utf8mb4;
@@ -434,7 +435,7 @@ CREATE TABLE IF NOT EXISTS `hook` (
`function` varchar(255) NOT NULL DEFAULT '',
`priority` int(11) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `hook_file_function` (`hook`(30),`file`(60),`function`(30))
UNIQUE INDEX `hook_file_function` (`hook`(50),`file`(80),`function`(60))
) DEFAULT CHARSET=utf8mb4;

--
@@ -1073,10 +1074,10 @@ CREATE TABLE IF NOT EXISTS `user` (
`expire_notification_sent` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`service_class` varchar(32) NOT NULL DEFAULT '',
`def_gid` int(11) NOT NULL DEFAULT 0,
`allow_cid` medium_text,
`allow_gid` medium_text,
`deny_cid` medium_text,
`deny_gid` medium_text,
`allow_cid` mediumtext,
`allow_gid` mediumtext,
`deny_cid` mediumtext,
`deny_gid` mediumtext,
`openidserver` text,
PRIMARY KEY(`uid`),
INDEX `nickname` (`nickname`(32))


+ 40
- 24
include/Core/Config.php Прегледај датотеку

@@ -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;
}

}

+ 9
- 8
include/cli_startup.php Прегледај датотеку

@@ -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'));



+ 4
- 2
include/create_shadowentry.php Прегледај датотеку

@@ -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;


+ 3
- 2
include/cron.php Прегледај датотеку

@@ -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") {


+ 3
- 3
include/cronhooks.php Прегледај датотеку

@@ -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") {


+ 3
- 2
include/cronjobs.php Прегледај датотеку

@@ -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'));



+ 1
- 2
include/dbclean.php Прегледај датотеку

@@ -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;


+ 3
- 2
include/dbstructure.php Прегледај датотеку

@@ -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(


+ 3
- 2
include/dbupdate.php Прегледај датотеку

@@ -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);
}


+ 4
- 2
include/delivery.php Прегледај датотеку

@@ -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();



+ 3
- 5
include/directory.php Прегледај датотеку

@@ -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();




+ 3
- 3
include/discover_poco.php Прегледај датотеку

@@ -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")


+ 8
- 7
include/expire.php Прегледај датотеку

@@ -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'));



+ 3
- 2
include/gprobe.php Прегледај датотеку

@@ -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'));



+ 5
- 2
include/notifier.php Прегледај датотеку

@@ -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();



+ 3
- 2
include/onepoll.php Прегледај датотеку

@@ -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'));



+ 1
- 2
include/pubsubpublish.php Прегледај датотеку

@@ -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") {


+ 4
- 2
include/queue.php Прегледај датотеку

@@ -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")


+ 4
- 2
include/remove_contact.php Прегледај датотеку

@@ -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;


+ 4
- 2
include/shadowupdate.php Прегледај датотеку

@@ -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();


+ 4
- 2
include/spool_post.php Прегледај датотеку

@@ -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();



+ 4
- 2
include/tagupdate.php Прегледај датотеку

@@ -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();


+ 4
- 2
include/threadupdate.php Прегледај датотеку

@@ -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();


+ 3
- 2
include/update_gcontact.php Прегледај датотеку

@@ -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'));



+ 3
- 2
index.php Прегледај датотеку

@@ -13,6 +13,8 @@
*
*/

use \Friendica\Core\Config;

require_once('boot.php');
require_once('object/BaseObject.php');

@@ -54,8 +56,7 @@ if(!$install) {
* Load configs from db. Overwrite configs from .htconfig.php
*/

load_config('config');
load_config('system');
Config::load();

if ($a->max_processes_reached() OR $a->maxload_reached()) {
header($_SERVER["SERVER_PROTOCOL"].' 503 Service Temporarily Unavailable');


+ 3
- 1
mod/friendica.php Прегледај датотеку

@@ -1,5 +1,7 @@
<?php

use \Friendica\Core\Config;

function friendica_init(App $a) {
if ($a->argv[1]=="json"){
$register_policy = Array('REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN');
@@ -29,7 +31,7 @@ function friendica_init(App $a) {
$visible_plugins[] = $rr['name'];
}

load_config('feature_lock');
Config::load('feature_lock');
$locked_features = array();
if(is_array($a->config['feature_lock']) && count($a->config['feature_lock'])) {
foreach($a->config['feature_lock'] as $k => $v) {


+ 5
- 3
util/maintenance.php Прегледај датотеку

@@ -1,5 +1,7 @@
<?php

use \Friendica\Core\Config;

require_once("boot.php");

$a = new App;
@@ -10,9 +12,9 @@ load_translation_table($lang);

require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data, false);
unset($db_host, $db_user, $db_pass, $db_data);
load_config('config');
load_config('system');
unset($db_host, $db_user, $db_pass, $db_data);
Config::load();

$maint_mode = 1;
if($argc > 1)


Loading…
Откажи
Сачувај