From c168d7d4cafe56178beb15de93dc3b0764b2b5b9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 17 Oct 2016 16:53:37 -0400 Subject: [PATCH 01/11] Enforce coding standards in Config.php and PConfig.php --- include/Core/Config.php | 11 ++++++----- include/Core/PConfig.php | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/Core/Config.php b/include/Core/Config.php index a93f188148..bc2bc1fad7 100644 --- a/include/Core/Config.php +++ b/include/Core/Config.php @@ -70,7 +70,7 @@ class Config { * If true the config is loaded from the db and not from the cache (default: false) * @return mixed Stored value or null if it does not exist */ - public static function get($family, $key, $default_value=null, $refresh = false) { + public static function get($family, $key, $default_value = null, $refresh = false) { global $a; @@ -123,14 +123,14 @@ class Config { * The value to store * @return mixed Stored $value or false if the database update failed */ - public static function set($family,$key,$value) { + public static function set($family, $key, $value) { global $a; $a->config[$family][$key] = $value; // manage array value - $dbvalue = (is_array($value)?serialize($value):$value); - $dbvalue = (is_bool($dbvalue) ? intval($dbvalue) : $dbvalue); + $dbvalue = is_array($value) ? serialize($value) : $value; + $dbvalue = is_bool($dbvalue) ? intval($dbvalue) : $dbvalue; $ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' ) ON DUPLICATE KEY UPDATE `v` = '%s'", @@ -139,8 +139,9 @@ ON DUPLICATE KEY UPDATE `v` = '%s'", dbesc($dbvalue), dbesc($dbvalue) ); - if($ret) + if ($ret) { return $value; + } return $ret; } diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index de8994d1de..c6821a2667 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -119,7 +119,7 @@ class PConfig { * The value to store * @return mixed Stored $value or false */ - public static function set($uid,$family,$key,$value) { + public static function set($uid, $family, $key, $value) { global $a; @@ -136,8 +136,9 @@ ON DUPLICATE KEY UPDATE `v` = '%s'", dbesc($dbvalue), dbesc($dbvalue) ); - if($ret) + if ($ret) { return $value; + } return $ret; } From 62bd32c1acefa5b8fb8c3261a304332308adbd9c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 17 Oct 2016 16:54:22 -0400 Subject: [PATCH 02/11] Improve performance of settings save by not querying the DB if submitted value is the same --- include/Core/Config.php | 4 ++++ include/Core/PConfig.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/include/Core/Config.php b/include/Core/Config.php index bc2bc1fad7..46972e1eb7 100644 --- a/include/Core/Config.php +++ b/include/Core/Config.php @@ -126,6 +126,10 @@ class Config { public static function set($family, $key, $value) { global $a; + if (self::get($family, $key) === $value) { + return true; + } + $a->config[$family][$key] = $value; // manage array value diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index c6821a2667..1d0f7fc82c 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -123,6 +123,10 @@ class PConfig { global $a; + if (self::get($uid, $family, $key) === $value) { + return true; + } + // manage array value $dbvalue = (is_array($value)?serialize($value):$value); From a5923bdd4fa46466a72b7dc2d9e9dd59911abda4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 17 Oct 2016 17:00:06 -0400 Subject: [PATCH 03/11] Wrong whitespaces --- include/Core/Config.php | 6 +++--- include/Core/PConfig.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/Core/Config.php b/include/Core/Config.php index 46972e1eb7..2f99c1aec4 100644 --- a/include/Core/Config.php +++ b/include/Core/Config.php @@ -126,9 +126,9 @@ class Config { public static function set($family, $key, $value) { global $a; - if (self::get($family, $key) === $value) { - return true; - } + if (self::get($family, $key) === $value) { + return true; + } $a->config[$family][$key] = $value; diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index 1d0f7fc82c..4523045f60 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -123,9 +123,9 @@ class PConfig { global $a; - if (self::get($uid, $family, $key) === $value) { - return true; - } + if (self::get($uid, $family, $key) === $value) { + return true; + } // manage array value $dbvalue = (is_array($value)?serialize($value):$value); From 74ce4c27107966ad85a1b810d180f52f7bddf64d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 21 Oct 2016 22:50:58 -0400 Subject: [PATCH 04/11] Makes save_timestamp conditional - Add a .htconfig check to save_timestamp to prevent systematic profiling - Removes unused `mark_timestamp()` function including deleted code comment --- boot.php | 8 +++----- object/Conversation.php | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/boot.php b/boot.php index f39fb0369c..0c25dfef3d 100644 --- a/boot.php +++ b/boot.php @@ -1100,6 +1100,9 @@ class App { } function save_timestamp($stamp, $value) { + if (!isset($a->config['system']['profiler']) || !$a->config['system']['profiler']) + return; + $duration = (float)(microtime(true)-$stamp); if (!isset($this->performance[$value])) { @@ -1176,11 +1179,6 @@ class App { return implode(", ", $callstack); } - function mark_timestamp($mark) { - //$this->performance["markstart"] -= microtime(true) - $this->performance["marktime"]; - $this->performance["markstart"] = microtime(true) - $this->performance["markstart"] - $this->performance["marktime"]; - } - function get_useragent() { return(FRIENDICA_PLATFORM." '".FRIENDICA_CODENAME."' ".FRIENDICA_VERSION."-".DB_UPDATE_VERSION."; ".$this->get_baseurl()); } diff --git a/object/Conversation.php b/object/Conversation.php index 94eed94d5f..36c06c6d62 100644 --- a/object/Conversation.php +++ b/object/Conversation.php @@ -145,7 +145,6 @@ class Conversation extends BaseObject { $result[] = $item_data; } - //$a->mark_timestamp(); return $result; } From 44d5dec06fbbc890a755b2b3e9b0f1ee80c74a64 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 21 Oct 2016 23:00:05 -0400 Subject: [PATCH 05/11] Improve logger performance - Reorder condition to prevent constant lookup (one-time ~3,500 substr) - Enforce coding standards --- include/text.php | 60 +++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/include/text.php b/include/text.php index 72fce41861..3e359f1a60 100644 --- a/include/text.php +++ b/include/text.php @@ -678,11 +678,13 @@ function attribute_contains($attr,$s) { return false; }} -if(! function_exists('logger')) { +if (! function_exists('logger')) { /* setup int->string log level map */ $LOGGER_LEVELS = array(); /** + * @brief Logs the given message at the given log level + * * log levels: * LOGGER_NORMAL (default) * LOGGER_TRACE @@ -692,51 +694,57 @@ $LOGGER_LEVELS = array(); * * @global App $a * @global dba $db + * @global array $LOGGER_LEVELS * @param string $msg * @param int $level */ -function logger($msg,$level = 0) { - // turn off logger in install mode +function logger($msg, $level = 0) { global $a; global $db; global $LOGGER_LEVELS; - if(($a->module == 'install') || (! ($db && $db->connected))) return; + $debugging = get_config('system','debugging'); + $logfile = get_config('system','logfile'); + $loglevel = intval(get_config('system','loglevel')); - if (count($LOGGER_LEVELS)==0){ - foreach (get_defined_constants() as $k=>$v){ - if (substr($k,0,7)=="LOGGER_") - $LOGGER_LEVELS[$v] = substr($k,7,7); + // turn off logger in install mode + if ( + $a->module == 'install' + || ! ($db && $db->connected) + || ! $debugging + || ! $logfile + || $level > $loglevel + ) { + return; + } + + if (count($LOGGER_LEVELS) == 0) { + foreach (get_defined_constants() as $k => $v){ + if (substr($k, 0, 7) == "LOGGER_") + $LOGGER_LEVELS[$v] = substr($k, 7, 7); } } - $debugging = get_config('system','debugging'); - $loglevel = intval(get_config('system','loglevel')); - $logfile = get_config('system','logfile'); - - if((! $debugging) || (! $logfile) || ($level > $loglevel)) - return; - $process_id = session_id(); - if ($process_id == "") + if ($process_id == '') { $process_id = get_app()->process_id; + } $callers = debug_backtrace(); - $logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n", - datetime_convert(), - $process_id, - $LOGGER_LEVELS[$level], - basename($callers[0]['file']), - $callers[0]['line'], - $callers[1]['function'], - $msg - ); + $logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n", + datetime_convert(), + $process_id, + $LOGGER_LEVELS[$level], + basename($callers[0]['file']), + $callers[0]['line'], + $callers[1]['function'], + $msg + ); $stamp1 = microtime(true); @file_put_contents($logfile, $logline, FILE_APPEND); $a->save_timestamp($stamp1, "file"); - return; }} From 9a59878190e91b3cfdeecd83fba2f0421cad25d0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 21 Oct 2016 23:08:42 -0400 Subject: [PATCH 06/11] Standards enforcing --- include/text.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/text.php b/include/text.php index 3e359f1a60..8f15ff2945 100644 --- a/include/text.php +++ b/include/text.php @@ -719,9 +719,10 @@ function logger($msg, $level = 0) { } if (count($LOGGER_LEVELS) == 0) { - foreach (get_defined_constants() as $k => $v){ - if (substr($k, 0, 7) == "LOGGER_") + foreach (get_defined_constants() as $k => $v) { + if (substr($k, 0, 7) == "LOGGER_") { $LOGGER_LEVELS[$v] = substr($k, 7, 7); + } } } From f9d713b228873436e6fd3f38c3cda374a582ac94 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 21 Oct 2016 23:23:44 -0400 Subject: [PATCH 07/11] Settings save: Switch from strict to fuzzy comparison --- include/Core/Config.php | 2 +- include/Core/PConfig.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Core/Config.php b/include/Core/Config.php index 2f99c1aec4..e82094417f 100644 --- a/include/Core/Config.php +++ b/include/Core/Config.php @@ -126,7 +126,7 @@ class Config { public static function set($family, $key, $value) { global $a; - if (self::get($family, $key) === $value) { + if (self::get($family, $key) == $value) { return true; } diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index 4523045f60..172a83e91d 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -123,7 +123,7 @@ class PConfig { global $a; - if (self::get($uid, $family, $key) === $value) { + if (self::get($uid, $family, $key) == $value) { return true; } From b806f878740299eea54e86603840bbfd596a4bf7 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 22 Oct 2016 13:54:30 -0400 Subject: [PATCH 08/11] Formatting changes to make @annando happy --- include/Core/Config.php | 2 +- include/Core/PConfig.php | 2 +- include/text.php | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/Core/Config.php b/include/Core/Config.php index e82094417f..ea6d9cda62 100644 --- a/include/Core/Config.php +++ b/include/Core/Config.php @@ -145,7 +145,7 @@ ON DUPLICATE KEY UPDATE `v` = '%s'", ); if ($ret) { return $value; - } + } return $ret; } diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index 172a83e91d..bd4883c0d3 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -142,7 +142,7 @@ ON DUPLICATE KEY UPDATE `v` = '%s'", ); if ($ret) { return $value; - } + } return $ret; } diff --git a/include/text.php b/include/text.php index 8f15ff2945..4b2a4a9409 100644 --- a/include/text.php +++ b/include/text.php @@ -734,14 +734,14 @@ function logger($msg, $level = 0) { $callers = debug_backtrace(); $logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n", - datetime_convert(), - $process_id, - $LOGGER_LEVELS[$level], - basename($callers[0]['file']), - $callers[0]['line'], - $callers[1]['function'], - $msg - ); + datetime_convert(), + $process_id, + $LOGGER_LEVELS[$level], + basename($callers[0]['file']), + $callers[0]['line'], + $callers[1]['function'], + $msg + ); $stamp1 = microtime(true); @file_put_contents($logfile, $logline, FILE_APPEND); From 2ecd1f5d09be3c3c0d43beea8a02fff2551d361a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 23 Oct 2016 07:57:40 -0400 Subject: [PATCH 09/11] Update settings documentation --- doc/htconfig.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/htconfig.md b/doc/htconfig.md index fa26236673..96910f1f69 100644 --- a/doc/htconfig.md +++ b/doc/htconfig.md @@ -1,14 +1,14 @@ Config values that can only be set in .htconfig.php =================================================== -There are some config values that haven't found their way into the administration page. This has several reasons. Maybe they are part of a -current development that isn't considered stable and will be added later in the administration page when it is considered safe. Or it triggers +There are some config values that haven't found their way into the administration page. This has several reasons. Maybe they are part of a +current development that isn't considered stable and will be added later in the administration page when it is considered safe. Or it triggers something that isn't expected to be of public interest. Or it is for testing purposes only. -**Attention:** Please be warned that you shouldn't use one of these values without the knowledge what it could trigger. Especially don't do that with +**Attention:** Please be warned that you shouldn't use one of these values without the knowledge what it could trigger. Especially don't do that with undocumented values. -The header of the section describes the category, the value is the parameter. Example: To set the directory value please add this +The header of the section describes the category, the value is the parameter. Example: To set the directory value please add this line to your .htconfig.php: $a->config['system']['directory'] = 'http://dir.friendi.ca'; @@ -23,7 +23,7 @@ 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. -* default_service_class - +* default_service_class - * delivery_batch_count - Number of deliveries per process. Default value is 1. (Disabled when using the worker) * diaspora_test (Boolean) - For development only. Disables the message transfer. * directory - The path to global directory. If not set then "http://dir.friendi.ca" is used. @@ -48,12 +48,13 @@ line to your .htconfig.php: * ostatus_poll_timeframe - Defines how old an item can be to try to complete the conversation with it. * paranoia (Boolean) - Log out users if their IP address changed. * permit_crawling (Boolean) - Restricts the search for not logged in users to one search per minute. +* profiler (Boolean) - Enable internal timings to help optimize code. Default is false. * free_crawls - Number of "free" searches when "permit_crawling" is activated (Default value is 10) * crawl_permit_period - Period in seconds between allowed searches when the number of free searches is reached and "permit_crawling" is activated (Default value is 60) * png_quality - Default value is 8. * proc_windows (Boolean) - Should be enabled if Friendica is running under Windows. * proxy_cache_time - Time after which the cache is cleared. Default value is one day. -* pushpoll_frequency - +* pushpoll_frequency - * qsearch_limit - Default value is 100. * relay_server - Experimental Diaspora feature. Address of the relay server where public posts should be send to. For example https://podrelay.net * relay_subscribe (Boolean) - Enables the receiving of public posts from the relay. They will be included in the search and on the community page when it is set up to show all public items. @@ -72,7 +73,7 @@ line to your .htconfig.php: ## service_class ## -* upgrade_link - +* upgrade_link - ## experimentals ## From d0b95e642f8df0d270610ea62ac23313c7168f4d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 24 Oct 2016 11:57:17 -0400 Subject: [PATCH 10/11] Reverted changes to config --- include/Core/Config.php | 4 ---- include/Core/PConfig.php | 4 ---- 2 files changed, 8 deletions(-) diff --git a/include/Core/Config.php b/include/Core/Config.php index ea6d9cda62..6ef394f2f1 100644 --- a/include/Core/Config.php +++ b/include/Core/Config.php @@ -126,10 +126,6 @@ class Config { public static function set($family, $key, $value) { global $a; - if (self::get($family, $key) == $value) { - return true; - } - $a->config[$family][$key] = $value; // manage array value diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index bd4883c0d3..c5e8335d88 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -123,10 +123,6 @@ class PConfig { global $a; - if (self::get($uid, $family, $key) == $value) { - return true; - } - // manage array value $dbvalue = (is_array($value)?serialize($value):$value); From 8da5a232677e60a9b62045e5f8308a3c4d265f8a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 24 Oct 2016 11:57:25 -0400 Subject: [PATCH 11/11] Improved doc formatting --- doc/htconfig.md | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/doc/htconfig.md b/doc/htconfig.md index 96910f1f69..c348f469b2 100644 --- a/doc/htconfig.md +++ b/doc/htconfig.md @@ -1,20 +1,19 @@ Config values that can only be set in .htconfig.php =================================================== -There are some config values that haven't found their way into the administration page. This has several reasons. Maybe they are part of a -current development that isn't considered stable and will be added later in the administration page when it is considered safe. Or it triggers -something that isn't expected to be of public interest. Or it is for testing purposes only. +There are some config values that haven't found their way into the administration page. +This has several reasons. +Maybe they are part of a current development that isn't considered stable and will be added later in the administration page when it is considered safe. +Or it triggers something that isn't expected to be of public interest. Or it is for testing purposes only. -**Attention:** Please be warned that you shouldn't use one of these values without the knowledge what it could trigger. Especially don't do that with -undocumented values. +**Attention:** Please be warned that you shouldn't use one of these values without the knowledge what it could trigger. +Especially don't do that with undocumented values. -The header of the section describes the category, the value is the parameter. Example: To set the directory value please add this -line to your .htconfig.php: +The header of the section describes the category, the value is the parameter. +Example: To set the directory value please add this line to your .htconfig.php: $a->config['system']['directory'] = 'http://dir.friendi.ca'; - - ## Jabber ## * debug (Boolean) - Enable debug level for the jabber account synchronisation. * logfile - Logfile for the jabber account synchronisation. @@ -48,7 +47,7 @@ line to your .htconfig.php: * ostatus_poll_timeframe - Defines how old an item can be to try to complete the conversation with it. * paranoia (Boolean) - Log out users if their IP address changed. * permit_crawling (Boolean) - Restricts the search for not logged in users to one search per minute. -* profiler (Boolean) - Enable internal timings to help optimize code. Default is false. +* profiler (Boolean) - Enable internal timings to help optimize code. Needed for "rendertime" addon. Default is false. * free_crawls - Number of "free" searches when "permit_crawling" is activated (Default value is 10) * crawl_permit_period - Period in seconds between allowed searches when the number of free searches is reached and "permit_crawling" is activated (Default value is 60) * png_quality - Default value is 8. @@ -85,19 +84,15 @@ line to your .htconfig.php: # Administrator Options # -Enabling the admin panel for an account, and thus making the account holder -admin of the node, is done by setting the variable +Enabling the admin panel for an account, and thus making the account holder admin of the node, is done by setting the variable $a->config['admin_email'] = "someone@example.com"; -where you have to match the email address used for the account with the one you -enter to the .htconfig file. If more then one account should be able to access -the admin panel, seperate the email addresses with a comma. +Where you have to match the email address used for the account with the one you enter to the .htconfig file. +If more then one account should be able to access the admin panel, seperate the email addresses with a comma. $a->config['admin_email'] = "someone@example.com,someonelese@example.com"; -If you want to have a more personalized closing line for the notification -emails you can set a variable for the admin_name. +If you want to have a more personalized closing line for the notification emails you can set a variable for the admin_name. $a->config['admin_name'] = "Marvin"; -