Merge pull request #3096 from annando/1701-index-again

Some more index stuff
This commit is contained in:
Tobias Diekershoff 2017-01-27 16:52:12 +01:00 committed by GitHub
commit 722b18ead7
54 changed files with 651 additions and 351 deletions

View file

@ -19,6 +19,8 @@
require_once('include/autoloader.php');
use \Friendica\Core\Config;
require_once('include/config.php');
require_once('include/network.php');
require_once('include/plugin.php');
@ -38,7 +40,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5.1-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1212 );
define ( 'DB_UPDATE_VERSION', 1213 );
/**
* @brief Constant with a HTML line break.
@ -823,24 +825,22 @@ class App {
$scheme = $this->scheme;
if ((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) {
if (intval($this->config['system']['ssl_policy']) === SSL_POLICY_FULL) {
if (Config::get('system', 'ssl_policy') === SSL_POLICY_FULL) {
$scheme = 'https';
}
// Basically, we have $ssl = true on any links which can only be seen by a logged in user
// (and also the login link). Anything seen by an outsider will have it turned off.
if (Config::get('system', 'ssl_policy') == SSL_POLICY_SELFSIGN) {
if ($ssl) {
$scheme = 'https';
}
// Basically, we have $ssl = true on any links which can only be seen by a logged in user
// (and also the login link). Anything seen by an outsider will have it turned off.
if ($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) {
if ($ssl) {
$scheme = 'https';
} else {
$scheme = 'http';
}
} else {
$scheme = 'http';
}
}
if (get_config('config', 'hostname') != '') {
if (Config::get('config', 'hostname') != '') {
$this->hostname = get_config('config', 'hostname');
}
@ -1391,11 +1391,15 @@ class App {
// If the last worker fork was less than 10 seconds before then don't fork another one.
// This should prevent the forking of masses of workers.
if (get_config("system", "worker")) {
if ((time() - get_config("system", "proc_run_started")) < 10)
return;
$cachekey = "app:proc_run:started";
$result = Cache::get($cachekey);
if (!is_null($result)) {
if ((time() - $result) < 10) {
return;
}
}
// Set the timestamp of the last proc_run
set_config("system", "proc_run_started", time());
Cache::set($cachekey, time(), CACHE_MINUTE);
}
$args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php');
@ -1475,9 +1479,7 @@ function system_unavailable() {
function clean_urls() {
$a = get_app();
// if($a->config['system']['clean_urls'])
return true;
// return false;
}
function z_path() {
@ -1571,7 +1573,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.
@ -2041,16 +2043,18 @@ function current_theme(){
// $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
$is_mobile = $a->is_mobile || $a->is_tablet;
$standard_system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : '');
$standard_system_theme = Config::get('system', 'theme', '');
$standard_theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $standard_system_theme);
if($is_mobile) {
if(isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
if ($is_mobile) {
if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
$system_theme = $standard_system_theme;
$theme_name = $standard_theme_name;
}
else {
$system_theme = ((isset($a->config['system']['mobile-theme'])) ? $a->config['system']['mobile-theme'] : $standard_system_theme);
} else {
$system_theme = Config::get('system', 'mobile-theme', '');
if ($system_theme == '') {
$system_theme = $standard_system_theme;
}
$theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme);
if($theme_name === '---') {

View file

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 3.5.1-dev (Asparagus)
-- DB_UPDATE_VERSION 1212
-- DB_UPDATE_VERSION 1213
-- ------------------------------------------
@ -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;
--
@ -55,11 +56,10 @@ CREATE TABLE IF NOT EXISTS `auth_codes` (
--
CREATE TABLE IF NOT EXISTS `cache` (
`k` varbinary(255) NOT NULL,
`v` text,
`v` mediumtext,
`expire_mode` int(11) NOT NULL DEFAULT 0,
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`k`),
INDEX `updated` (`updated`),
INDEX `expire_mode_updated` (`expire_mode`,`updated`)
) DEFAULT CHARSET=utf8mb4;
@ -96,7 +96,7 @@ CREATE TABLE IF NOT EXISTS `config` (
`id` int(10) unsigned NOT NULL auto_increment,
`cat` varbinary(255) NOT NULL DEFAULT '',
`k` varbinary(255) NOT NULL DEFAULT '',
`v` text,
`v` mediumtext,
PRIMARY KEY(`id`),
UNIQUE INDEX `cat_k` (`cat`,`k`)
) DEFAULT CHARSET=utf8mb4;
@ -172,18 +172,20 @@ CREATE TABLE IF NOT EXISTS `contact` (
`bd` date NOT NULL DEFAULT '0000-00-00',
`notify_new_posts` tinyint(1) NOT NULL DEFAULT 0,
`fetch_further_information` tinyint(1) NOT NULL DEFAULT 0,
`ffi_keyword_blacklist` mediumtext,
`ffi_keyword_blacklist` text,
PRIMARY KEY(`id`),
INDEX `uid_name` (`uid`,`name`),
INDEX `uid_self` (`uid`,`self`),
INDEX `self_uid` (`self`,`uid`),
INDEX `alias_uid` (`alias`(32),`uid`),
INDEX `uid_pending` (`uid`,`pending`),
INDEX `uid_blocked` (`uid`,`blocked`),
INDEX `pending_uid` (`pending`,`uid`),
INDEX `blocked_uid` (`blocked`,`uid`),
INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`,`poll`(64),`archive`),
INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)),
INDEX `addr_uid` (`addr`(32),`uid`),
INDEX `nurl_uid` (`nurl`(32),`uid`),
INDEX `nick_uid` (`nick`(32),`uid`)
INDEX `nick_uid` (`nick`(32),`uid`),
INDEX `dfrn-id` (`dfrn-id`),
INDEX `issued-id` (`issued-id`)
) DEFAULT CHARSET=utf8mb4;
--
@ -192,12 +194,12 @@ CREATE TABLE IF NOT EXISTS `contact` (
CREATE TABLE IF NOT EXISTS `conv` (
`id` int(10) unsigned NOT NULL auto_increment,
`guid` varchar(64) NOT NULL DEFAULT '',
`recips` mediumtext,
`recips` text,
`uid` int(11) NOT NULL DEFAULT 0,
`creator` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`subject` mediumtext,
`subject` text,
PRIMARY KEY(`id`),
INDEX `uid` (`uid`)
) DEFAULT CHARSET=utf8mb4;
@ -264,7 +266,8 @@ CREATE TABLE IF NOT EXISTS `fcontact` (
`pubkey` text,
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`),
INDEX `addr` (`addr`(32))
INDEX `addr` (`addr`(32)),
INDEX `url` (`url`)
) DEFAULT CHARSET=utf8mb4;
--
@ -349,10 +352,11 @@ CREATE TABLE IF NOT EXISTS `gcontact` (
`generation` tinyint(3) NOT NULL DEFAULT 0,
`server_url` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`),
INDEX `nurl` (`nurl`(32)),
INDEX `name` (`name`(32)),
INDEX `nurl` (`nurl`(64)),
INDEX `name` (`name`(64)),
INDEX `nick` (`nick`(32)),
INDEX `addr` (`addr`(32)),
INDEX `addr` (`addr`(64)),
INDEX `hide_network_updated` (`hide`,`network`,`updated`),
INDEX `updated` (`updated`)
) DEFAULT CHARSET=utf8mb4;
@ -368,8 +372,7 @@ CREATE TABLE IF NOT EXISTS `glink` (
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`),
UNIQUE INDEX `cid_uid_gcid_zcid` (`cid`,`uid`,`gcid`,`zcid`),
INDEX `gcid` (`gcid`),
INDEX `zcid` (`zcid`)
INDEX `gcid` (`gcid`)
) DEFAULT CHARSET=utf8mb4;
--
@ -394,8 +397,8 @@ CREATE TABLE IF NOT EXISTS `group_member` (
`gid` int(10) unsigned NOT NULL DEFAULT 0,
`contact-id` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `cid_contactid` (`cid`,`contact-id`),
INDEX `uid_contactid` (`uid`,`contact-id`),
INDEX `contactid` (`contact-id`),
INDEX `gid_contactid` (`gid`,`contact-id`),
UNIQUE INDEX `uid_gid_contactid` (`uid`,`gid`,`contact-id`)
) DEFAULT CHARSET=utf8mb4;
@ -432,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;
--
@ -532,18 +535,13 @@ CREATE TABLE IF NOT EXISTS `item` (
INDEX `uid_created` (`uid`,`created`),
INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
INDEX `uid_network_received` (`uid`,`network`,`received`),
INDEX `uid_received` (`uid`,`received`),
INDEX `uid_network_commented` (`uid`,`network`,`commented`),
INDEX `uid_title` (`uid`,`title`),
INDEX `uid_thrparent` (`uid`,`thr-parent`),
INDEX `uid_parenturi` (`uid`,`parent-uri`),
INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
INDEX `authorid_created` (`author-id`,`created`),
INDEX `uid_uri` (`uid`,`uri`),
INDEX `uid_wall_created` (`uid`,`wall`,`created`),
INDEX `resource-id` (`resource-id`),
INDEX `uid_type` (`uid`,`type`),
INDEX `contactid_allowcid_allowpid_denycid_denygid` (`contact-id`,`allow_cid`(10),`allow_gid`(10),`deny_cid`(10),`deny_gid`(10)),
INDEX `uid_type_changed` (`uid`,`type`,`changed`),
INDEX `contactid_verb` (`contact-id`,`verb`),
@ -603,7 +601,6 @@ CREATE TABLE IF NOT EXISTS `mail` (
`parent-uri` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`),
INDEX `uid` (`uid`),
INDEX `uid_seen` (`uid`,`seen`),
INDEX `convid` (`convid`),
INDEX `uri` (`uri`(64)),
@ -638,7 +635,7 @@ CREATE TABLE IF NOT EXISTS `manage` (
`uid` int(11) NOT NULL DEFAULT 0,
`mid` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `uid_mid` (`uid`,`mid`)
UNIQUE INDEX `uid_mid` (`uid`,`mid`)
) DEFAULT CHARSET=utf8mb4;
--
@ -663,11 +660,10 @@ CREATE TABLE IF NOT EXISTS `notify` (
`name_cache` tinytext,
`msg_cache` mediumtext,
PRIMARY KEY(`id`),
INDEX `uid_hash` (`uid`,`hash`),
INDEX `uid_seen_date` (`uid`,`seen`,`date`),
INDEX `uid_type_link` (`uid`,`type`,`link`),
INDEX `uid_link` (`uid`,`link`),
INDEX `uid_date` (`uid`,`date`)
INDEX `hash_uid` (`hash`,`uid`),
INDEX `seen_uid_date` (`seen`,`uid`,`date`),
INDEX `uid_date` (`uid`,`date`),
INDEX `uid_type_link` (`uid`,`type`,`link`)
) DEFAULT CHARSET=utf8mb4;
--
@ -679,8 +675,7 @@ CREATE TABLE IF NOT EXISTS `notify-threads` (
`master-parent-item` int(10) unsigned NOT NULL DEFAULT 0,
`parent-item` int(10) unsigned NOT NULL DEFAULT 0,
`receiver-uid` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `master-parent-item` (`master-parent-item`)
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8mb4;
--
@ -688,7 +683,7 @@ CREATE TABLE IF NOT EXISTS `notify-threads` (
--
CREATE TABLE IF NOT EXISTS `oembed` (
`url` varbinary(255) NOT NULL,
`content` text,
`content` mediumtext,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`url`),
INDEX `created` (`created`)
@ -701,7 +696,7 @@ CREATE TABLE IF NOT EXISTS `parsed_url` (
`url` varbinary(255) NOT NULL,
`guessing` tinyint(1) NOT NULL DEFAULT 0,
`oembed` tinyint(1) NOT NULL DEFAULT 0,
`content` text,
`content` mediumtext,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`url`,`guessing`,`oembed`),
INDEX `created` (`created`)
@ -749,7 +744,7 @@ CREATE TABLE IF NOT EXISTS `photo` (
PRIMARY KEY(`id`),
INDEX `uid_contactid` (`uid`,`contact-id`),
INDEX `uid_profile` (`uid`,`profile`),
INDEX `uid_album_created` (`uid`,`album`(32),`created`),
INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`(64),`created`),
INDEX `resource-id` (`resource-id`(64))
) DEFAULT CHARSET=utf8mb4;
@ -760,16 +755,16 @@ CREATE TABLE IF NOT EXISTS `photo` (
CREATE TABLE IF NOT EXISTS `poll` (
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`q0` mediumtext,
`q1` mediumtext,
`q2` mediumtext,
`q3` mediumtext,
`q4` mediumtext,
`q5` mediumtext,
`q6` mediumtext,
`q7` mediumtext,
`q8` mediumtext,
`q9` mediumtext,
`q0` text,
`q1` text,
`q2` text,
`q3` text,
`q4` text,
`q5` text,
`q6` text,
`q7` text,
`q8` text,
`q9` text,
PRIMARY KEY(`id`),
INDEX `uid` (`uid`)
) DEFAULT CHARSET=utf8mb4;
@ -843,7 +838,8 @@ CREATE TABLE IF NOT EXISTS `profile` (
`thumb` varchar(255) NOT NULL DEFAULT '',
`publish` tinyint(1) NOT NULL DEFAULT 0,
`net-publish` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
PRIMARY KEY(`id`),
INDEX `uid_is-default` (`uid`,`is-default`)
) DEFAULT CHARSET=utf8mb4;
--
@ -979,8 +975,6 @@ CREATE TABLE IF NOT EXISTS `term` (
`uid` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`tid`),
INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`),
INDEX `uid_term_tid` (`uid`,`term`(32),`tid`),
INDEX `type_term` (`type`,`term`(32)),
INDEX `uid_otype_type_term_global_created` (`uid`,`otype`,`type`,`term`(32),`global`,`created`),
INDEX `uid_otype_type_url` (`uid`,`otype`,`type`,`url`(64)),
INDEX `guid` (`guid`(64))
@ -1017,8 +1011,6 @@ CREATE TABLE IF NOT EXISTS `thread` (
`mention` tinyint(1) NOT NULL DEFAULT 0,
`network` varchar(32) NOT NULL DEFAULT '',
PRIMARY KEY(`iid`),
INDEX `created` (`created`),
INDEX `commented` (`commented`),
INDEX `uid_network_commented` (`uid`,`network`,`commented`),
INDEX `uid_network_created` (`uid`,`network`,`created`),
INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
@ -1111,7 +1103,6 @@ CREATE TABLE IF NOT EXISTS `workerqueue` (
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`pid` int(11) NOT NULL DEFAULT 0,
`executed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`),
INDEX `created` (`created`)
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8mb4;

View file

@ -26,6 +26,13 @@ Example: To set the directory value please add this line to your .htconfig.php:
* **birthday_input_format** - Default value is "ymd".
* **block_local_dir** (Boolean) - Blocks the access to the directory of the local users.
* **curl_range_bytes** - Maximum number of bytes that should be fetched. Default is 0, which mean "no limit".
* **db_log** - Name of a logfile to log slow database queries
* **db_loglimit** - If a database call lasts longer than this value it is logged
* **db_log_index** - Name of a logfile to log queries with bad indexes
* **db_log_index_watch** - Watchlist of indexes to watch
* **db_loglimit_index** - Number of index rows needed to be logged for indexes on the watchlist
* **db_loglimit_index_high** - Number of index rows to be logged anyway (for any index)
* **db_log_index_blacklist** - Blacklist of indexes that shouldn't be watched
* **dbclean** (Boolean) - Enable the automatic database cleanup process
* **default_service_class** -
* **delivery_batch_count** - Number of deliveries per process. Default value is 1. (Disabled when using the worker)

View file

@ -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;
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v']) ? unserialize($ret[0]['v']) : $ret[0]['v']);
// 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;
}
@ -128,17 +139,28 @@ class Config {
public static function set($family, $key, $value) {
$a = get_app();
// We store our setting values in a string variable.
// So we have to do the conversion here so that the compare below works.
// The exception are array values.
$dbvalue = (!is_array($value) ? (string)$value : $value);
$stored = self::get($family, $key);
if ($stored == $value) {
if ($stored === $dbvalue) {
return true;
}
$a->config[$family][$key] = $value;
if ($family === 'config') {
$a->config[$key] = $dbvalue;
} elseif ($family != 'system') {
$a->config[$family][$key] = $dbvalue;
}
// Assign the just added value to the cache
self::$cache[$family][$key] = $dbvalue;
// manage array value
$dbvalue = (is_array($value) ? serialize($value) : $value);
$dbvalue = (is_bool($dbvalue) ? intval($dbvalue) : $dbvalue);
$dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
if (is_null($stored)) {
$ret = q("INSERT INTO `config` (`cat`, `k`, `v`) VALUES ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE `v` = '%s'",
@ -174,9 +196,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 +206,4 @@ class Config {
return $ret;
}
}

View file

@ -495,6 +495,8 @@ function acl_lookup(App $a, $out_type = 'json') {
if ($type=='' || $type=='g'){
/// @todo We should cache this query.
// This can be done when we can delete cache entries via wildcard
$r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') AS uids
FROM `group`
INNER JOIN `group_member` ON `group_member`.`gid`=`group`.`id` AND `group_member`.`uid` = `group`.`uid`

View file

@ -5,6 +5,9 @@
*
* @todo Automatically detect if incoming data is HTML or BBCode
*/
use \Friendica\Core\Config;
require_once('include/HTTPExceptions.php');
require_once('include/bbcode.php');
@ -2696,11 +2699,11 @@
$logo = App::get_baseurl() . '/images/friendica-64.png';
$email = $a->config['admin_email'];
$closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
$private = (($a->config['system']['block_public']) ? 'true' : 'false');
$private = ((Config::get('system', 'block_public')) ? 'true' : 'false');
$textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000);
if($a->config['api_import_size'])
$texlimit = string($a->config['api_import_size']);
$ssl = (($a->config['system']['have_ssl']) ? 'true' : 'false');
$ssl = ((Config::get('system', 'have_ssl')) ? 'true' : 'false');
$sslserver = (($ssl === 'true') ? str_replace('http:','https:',App::get_baseurl()) : '');
$config = array(

View file

@ -186,7 +186,7 @@ class Cache {
set_config("system", "cache_cleared_half_hour", time());
}
if (($max_level <= CACHE_QUARTER_HOUR) AND (get_config("system", "cache_cleared_hour")) < time() - self::duration(CACHE_QUARTER_HOUR)) {
if (($max_level <= CACHE_QUARTER_HOUR) AND (get_config("system", "cache_cleared_quarter_hour")) < time() - self::duration(CACHE_QUARTER_HOUR)) {
q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
dbesc(datetime_convert('UTC','UTC',"now - 15 minutes")), intval(CACHE_QUARTER_HOUR));

View file

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

View file

@ -90,7 +90,7 @@ function networks_widget($baseurl,$selected = '') {
$extra_sql = unavailable_networks();
$r = q("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = %d AND NOT `self` $extra_sql ORDER BY `network`",
$r = q("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = %d AND `network` != '' $extra_sql ORDER BY `network`",
intval(local_user())
);

View file

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

View file

@ -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") {
@ -239,11 +240,13 @@ function cron_poll_contacts($argc, $argv) {
: ''
);
$contacts = q("SELECT `contact`.`id` FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
WHERE `rel` IN (%d, %d) AND `poll` != '' AND `network` IN ('%s', '%s', '%s', '%s', '%s', '%s')
$sql_extra
AND NOT `self` AND NOT `contact`.`blocked` AND NOT `contact`.`readonly` AND NOT `contact`.`archive`
AND NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql ORDER BY RAND()",
$contacts = q("SELECT `contact`.`id` FROM `user`
STRAIGHT_JOIN `contact`
ON `contact`.`uid` = `user`.`uid` AND `contact`.`rel` IN (%d, %d) AND `contact`.`poll` != ''
AND `contact`.`network` IN ('%s', '%s', '%s', '%s', '%s', '%s') $sql_extra
AND NOT `contact`.`self` AND NOT `contact`.`blocked` AND NOT `contact`.`readonly`
AND NOT `contact`.`archive`
WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql ORDER BY RAND()",
intval(CONTACT_IS_SHARING),
intval(CONTACT_IS_FRIEND),
dbesc(NETWORK_DFRN),

View file

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

View file

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

View file

@ -4,6 +4,7 @@
* @brief Some functions for date and time related tasks.
*/
use \Friendica\Core\Config;
/**
* @brief Two-level sort for timezones.
@ -271,8 +272,9 @@ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicke
$lang = substr(get_browser_language(), 0, 2);
// Check if the detected language is supported by the picker
if (!in_array($lang, array("ar", "ro", "id", "bg", "fa", "ru", "uk", "en", "el", "de", "nl", "tr", "fr", "es", "th", "pl", "pt", "ch", "se", "kr", "it", "da", "no", "ja", "vi", "sl", "cs", "hu")))
$lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
if (!in_array($lang, array("ar", "ro", "id", "bg", "fa", "ru", "uk", "en", "el", "de", "nl", "tr", "fr", "es", "th", "pl", "pt", "ch", "se", "kr", "it", "da", "no", "ja", "vi", "sl", "cs", "hu"))) {
$lang = Config::get('system', 'language', 'en');
}
$o = '';
$dateformat = '';

View file

@ -138,6 +138,62 @@ class dba {
return $return;
}
/**
* @brief Analyze a database query and log this if some conditions are met.
*
* @param string $query The database query that will be analyzed
*/
public function log_index($query) {
$a = get_app();
if ($a->config["system"]["db_log_index"] == "") {
return;
}
// Don't explain an explain statement
if (strtolower(substr($query, 0, 7)) == "explain") {
return;
}
// Only do the explain on "select", "update" and "delete"
if (!in_array(strtolower(substr($query, 0, 6)), array("select", "update", "delete"))) {
return;
}
$r = $this->q("EXPLAIN ".$query);
if (!dbm::is_result($r)) {
return;
}
$watchlist = explode(',', $a->config["system"]["db_log_index_watch"]);
$blacklist = explode(',', $a->config["system"]["db_log_index_blacklist"]);
foreach ($r AS $row) {
if ((intval($a->config["system"]["db_loglimit_index"]) > 0)) {
$log = (in_array($row['key'], $watchlist) AND
($row['rows'] >= intval($a->config["system"]["db_loglimit_index"])));
} else
$log = false;
if ((intval($a->config["system"]["db_loglimit_index_high"]) > 0) AND ($row['rows'] >= intval($a->config["system"]["db_loglimit_index_high"]))) {
$log = true;
}
if (in_array($row['key'], $blacklist) OR ($row['key'] == "")) {
$log = false;
}
if ($log) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
@file_put_contents($a->config["system"]["db_log_index"], datetime_convert()."\t".
$row['key']."\t".$row['rows']."\t".$row['Extra']."\t".
basename($backtrace[1]["file"])."\t".
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
substr($query, 0, 2000)."\n", FILE_APPEND);
}
}
}
public function q($sql, $onlyquery = false) {
$a = get_app();
@ -375,6 +431,9 @@ function q($sql) {
//logger("dba: q: $stmt", LOGGER_ALL);
if ($stmt === false)
logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true), LOGGER_DEBUG);
$db->log_index($stmt);
return $db->q($stmt);
}
@ -408,6 +467,9 @@ function qu($sql) {
$stmt = @vsprintf($sql,$args); // Disabled warnings
if ($stmt === false)
logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true), LOGGER_DEBUG);
$db->log_index($stmt);
$db->q("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
$retval = $db->q($stmt);
$db->q("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;");

View file

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

View file

@ -176,15 +176,6 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
$definition = db_definition($charset);
}
// Ensure index conversion to unique removes duplicates
$sql_config = "SET session old_alter_table=1;";
if ($verbose) {
echo $sql_config."\n";
}
if ($action) {
$db->q($sql_config);
}
// MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
if ((version_compare($db->server_info(), '5.7.4') >= 0) AND
!(strpos($db->server_info(), 'MariaDB') !== false)) {
@ -204,6 +195,27 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
}
$is_new_table = True;
} else {
$is_unique = false;
$temp_name = $name;
foreach ($structure["indexes"] AS $indexname => $fieldnames) {
if (isset($database[$name]["indexes"][$indexname])) {
$current_index_definition = implode(",",$database[$name]["indexes"][$indexname]);
} else {
$current_index_definition = "__NOT_SET__";
}
$new_index_definition = implode(",",$fieldnames);
if ($current_index_definition != $new_index_definition) {
if ($fieldnames[0] == "UNIQUE") {
$is_unique = true;
// Deactivated. See below for the reason
//if ($ignore == "") {
// $temp_name = "temp-".$name;
//}
}
}
}
/*
* Drop the index if it isn't present in the definition
* or the definition differ from current status
@ -219,7 +231,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if ($current_index_definition != $new_index_definition && substr($indexname, 0, 6) != 'local_') {
$sql2=db_drop_index($indexname);
if ($sql3 == "") {
$sql3 = "ALTER".$ignore." TABLE `".$name."` ".$sql2;
$sql3 = "ALTER".$ignore." TABLE `".$temp_name."` ".$sql2;
} else {
$sql3 .= ", ".$sql2;
}
@ -230,7 +242,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if (!isset($database[$name]["fields"][$fieldname])) {
$sql2=db_add_table_field($fieldname, $parameters);
if ($sql3 == "") {
$sql3 = "ALTER TABLE `".$name."` ".$sql2;
$sql3 = "ALTER TABLE `".$temp_name."` ".$sql2;
} else {
$sql3 .= ", ".$sql2;
}
@ -241,7 +253,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if ($current_field_definition != $new_field_definition) {
$sql2=db_modify_table_field($fieldname, $parameters);
if ($sql3 == "") {
$sql3 = "ALTER TABLE `".$name."` ".$sql2;
$sql3 = "ALTER TABLE `".$temp_name."` ".$sql2;
} else {
$sql3 .= ", ".$sql2;
}
@ -268,7 +280,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
$sql2=db_create_index($indexname, $fieldnames);
if ($sql2 != "") {
if ($sql3 == "")
$sql3 = "ALTER" . $ignore . " TABLE `".$name."` ".$sql2;
$sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
else
$sql3 .= ", ".$sql2;
}
@ -278,13 +290,77 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if ($sql3 != "") {
$sql3 .= ";";
if ($verbose)
if ($verbose) {
// Ensure index conversion to unique removes duplicates
if ($is_unique) {
// By now the alternative is commented out.
// This is a preparation for the time when we found a good SQL routine.
//if ($ignore != "") {
echo "SET session old_alter_table=1;\n";
//} else {
// echo "CREATE TABLE `".$temp_name."` LIKE `".$name."`;\n";
//}
}
echo $sql3."\n";
if ($is_unique) {
// By now the alternative is commented out.
// This is a preparation for the time when we found a good SQL routine.
//if ($ignore != "") {
echo "SET session old_alter_table=0;\n";
//} else {
// echo "INSERT IGNORE INTO `".$temp_name."` SELECT * FROM `".$name."`;\n";
// echo "DROP TABLE `".$name."`;\n";
// echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
//}
}
}
if ($action) {
// Ensure index conversion to unique removes duplicates
if ($is_unique) {
// By now the alternative is commented out.
// This is a preparation for the time when we found a good SQL routine.
//if ($ignore != "") {
$db->q("SET session old_alter_table=1;");
//} else {
// $r = $db->q("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
// if (!dbm::is_result($r)) {
// $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
// return $errors;
// }
//}
}
$r = @$db->q($sql3);
if (dbm::is_result($r))
if (!dbm::is_result($r))
$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
if ($is_unique) {
// By now the alternative is commented out.
// This is a preparation for the time when we found a good SQL routine.
//if ($ignore != "") {
$db->q("SET session old_alter_table=0;");
//} else {
// We have to check if "INSERT IGNORE" will work on newer MySQL versions
// $r = $db->q("INSERT IGNORE INTO `".$temp_name."` SELECT * FROM `".$name."`;");
// if (!dbm::is_result($r)) {
// $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
// return $errors;
// }
// $r = $db->q("DROP TABLE `".$name."`;");
// if (!dbm::is_result($r)) {
// $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
// return $errors;
// }
// $r = $db->q("RENAME TABLE `".$temp_name."` TO `".$name."`;");
// if (!dbm::is_result($r)) {
// $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
// return $errors;
// }
//}
}
}
}
}
@ -419,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"),
@ -428,6 +504,7 @@ function db_definition($charset) {
),
"indexes" => array(
"PRIMARY" => array("id"),
"name" => array("UNIQUE", "name"),
)
);
$database["attach"] = array(
@ -465,13 +542,12 @@ function db_definition($charset) {
$database["cache"] = array(
"fields" => array(
"k" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
"v" => array("type" => "text"),
"v" => array("type" => "mediumtext"),
"expire_mode" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
),
"indexes" => array(
"PRIMARY" => array("k"),
"updated" => array("updated"),
"expire_mode_updated" => array("expire_mode", "updated"),
)
);
@ -506,7 +582,7 @@ function db_definition($charset) {
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"cat" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
"k" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
"v" => array("type" => "text"),
"v" => array("type" => "mediumtext"),
),
"indexes" => array(
"PRIMARY" => array("id"),
@ -582,32 +658,34 @@ function db_definition($charset) {
"bd" => array("type" => "date", "not null" => "1", "default" => "0000-00-00"),
"notify_new_posts" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"fetch_further_information" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"ffi_keyword_blacklist" => array("type" => "mediumtext"),
"ffi_keyword_blacklist" => array("type" => "text"),
),
"indexes" => array(
"PRIMARY" => array("id"),
"uid_name" => array("uid", "name"),
"uid_self" => array("uid", "self"),
"self_uid" => array("self", "uid"),
"alias_uid" => array("alias(32)", "uid"),
"uid_pending" => array("uid", "pending"),
"uid_blocked" => array("uid", "blocked"),
"pending_uid" => array("pending", "uid"),
"blocked_uid" => array("blocked", "uid"),
"uid_rel_network_poll" => array("uid", "rel", "network", "poll(64)", "archive"),
"uid_network_batch" => array("uid", "network", "batch(64)"),
"addr_uid" => array("addr(32)", "uid"),
"nurl_uid" => array("nurl(32)", "uid"),
"nick_uid" => array("nick(32)", "uid"),
"dfrn-id" => array("dfrn-id"),
"issued-id" => array("issued-id"),
)
);
$database["conv"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
"recips" => array("type" => "mediumtext"),
"recips" => array("type" => "text"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"creator" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),