mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-17 01:25:21 +02:00
Merge pull request #2862 from Hypolite/settings-save-perf
Performance improvements: Settings save (alt), profiler, logger
This commit is contained in:
commit
4fdced1a0a
6 changed files with 63 additions and 59 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,58 @@ $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;
|
||||
}}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue