Merge pull request #8931 from MrPetovan/task/2020-performance-improvements
Various performance improvements
This commit is contained in:
commit
74bc3de472
21 changed files with 203 additions and 100 deletions
|
@ -136,7 +136,7 @@ class Addon
|
|||
$func();
|
||||
}
|
||||
|
||||
DBA::delete('hook', ['file' => 'addon/' . $addon . '/' . $addon . '.php']);
|
||||
Hook::delete(['file' => 'addon/' . $addon . '/' . $addon . '.php']);
|
||||
|
||||
unset(self::$addons[array_search($addon, self::$addons)]);
|
||||
}
|
||||
|
@ -204,17 +204,9 @@ class Addon
|
|||
}
|
||||
|
||||
Logger::notice("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $addon['name']]);
|
||||
@include_once($fname);
|
||||
|
||||
if (function_exists($addonname . '_uninstall')) {
|
||||
$func = $addonname . '_uninstall';
|
||||
$func(DI::app());
|
||||
}
|
||||
if (function_exists($addonname . '_install')) {
|
||||
$func = $addonname . '_install';
|
||||
$func(DI::app());
|
||||
}
|
||||
DBA::update('addon', ['timestamp' => $t], ['id' => $addon['id']]);
|
||||
self::uninstall($fname);
|
||||
self::install($fname);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,7 +248,7 @@ class Addon
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
$f = file_get_contents("addon/$addon/$addon.php");
|
||||
DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
|
||||
DI::profiler()->saveTimestamp($stamp1, "file");
|
||||
|
||||
$r = preg_match("|/\*.*\*/|msU", $f, $m);
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
|||
|
||||
$return = $this->cache->getAllKeys($prefix);
|
||||
|
||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
||||
$this->profiler->saveTimestamp($time, 'cache');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
|||
|
||||
$return = $this->cache->get($key);
|
||||
|
||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
||||
$this->profiler->saveTimestamp($time, 'cache');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
|||
|
||||
$return = $this->cache->set($key, $value, $ttl);
|
||||
|
||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
||||
$this->profiler->saveTimestamp($time, 'cache');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
|||
|
||||
$return = $this->cache->delete($key);
|
||||
|
||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
||||
$this->profiler->saveTimestamp($time, 'cache');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
|||
|
||||
$return = $this->cache->clear($outdated);
|
||||
|
||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
||||
$this->profiler->saveTimestamp($time, 'cache');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
|||
|
||||
$return = $this->cache->add($key, $value, $ttl);
|
||||
|
||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
||||
$this->profiler->saveTimestamp($time, 'cache');
|
||||
|
||||
return $return;
|
||||
} else {
|
||||
|
@ -145,7 +145,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
|||
|
||||
$return = $this->cache->compareSet($key, $oldValue, $newValue, $ttl);
|
||||
|
||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
||||
$this->profiler->saveTimestamp($time, 'cache');
|
||||
|
||||
return $return;
|
||||
} else {
|
||||
|
@ -163,7 +163,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
|||
|
||||
$return = $this->cache->compareDelete($key, $value);
|
||||
|
||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
||||
$this->profiler->saveTimestamp($time, 'cache');
|
||||
|
||||
return $return;
|
||||
} else {
|
||||
|
|
|
@ -99,9 +99,7 @@ class Hook
|
|||
return true;
|
||||
}
|
||||
|
||||
$result = DBA::insert('hook', ['hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority]);
|
||||
|
||||
return $result;
|
||||
return self::insert(['hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,10 +117,10 @@ class Hook
|
|||
|
||||
// This here is only needed for fixing a problem that existed on the develop branch
|
||||
$condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
|
||||
DBA::delete('hook', $condition);
|
||||
self::delete($condition);
|
||||
|
||||
$condition = ['hook' => $hook, 'file' => $relative_file, 'function' => $function];
|
||||
$result = DBA::delete('hook', $condition);
|
||||
$result = self::delete($condition);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -220,7 +218,7 @@ class Hook
|
|||
} else {
|
||||
// remove orphan hooks
|
||||
$condition = ['hook' => $name, 'file' => $hook[0], 'function' => $hook[1]];
|
||||
DBA::delete('hook', $condition, ['cascade' => false]);
|
||||
self::delete($condition, ['cascade' => false]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,4 +243,45 @@ class Hook
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes one or more hook records
|
||||
*
|
||||
* We have to clear the cached routerDispatchData because addons can provide routes
|
||||
*
|
||||
* @param array $condition
|
||||
* @param array $options
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function delete(array $condition, array $options = [])
|
||||
{
|
||||
$result = DBA::delete('hook', $condition, $options);
|
||||
|
||||
if ($result) {
|
||||
DI::cache()->delete('routerDispatchData');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a hook record
|
||||
*
|
||||
* We have to clear the cached routerDispatchData because addons can provide routes
|
||||
*
|
||||
* @param array $condition
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function insert(array $condition)
|
||||
{
|
||||
$result = DBA::insert('hook', $condition);
|
||||
|
||||
if ($result) {
|
||||
DI::cache()->delete('routerDispatchData');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ class Renderer
|
|||
throw new InternalServerErrorException($message);
|
||||
}
|
||||
|
||||
DI::profiler()->saveTimestamp($stamp1, "rendering", System::callstack());
|
||||
DI::profiler()->saveTimestamp($stamp1, "rendering");
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ class Renderer
|
|||
throw new InternalServerErrorException($message);
|
||||
}
|
||||
|
||||
DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
|
||||
DI::profiler()->saveTimestamp($stamp1, "file");
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
|
|
@ -33,16 +33,17 @@ class System
|
|||
/**
|
||||
* Returns a string with a callstack. Can be used for logging.
|
||||
*
|
||||
* @param integer $depth optional, default 4
|
||||
* @param integer $depth How many calls to include in the stacks after filtering
|
||||
* @param int $offset How many calls to shave off the top of the stack, for example if
|
||||
* this is called from a centralized method that isn't relevant to the callstack
|
||||
* @return string
|
||||
*/
|
||||
public static function callstack($depth = 4)
|
||||
public static function callstack(int $depth = 4, int $offset = 0)
|
||||
{
|
||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
|
||||
// We remove the first two items from the list since they contain data that we don't need.
|
||||
array_shift($trace);
|
||||
array_shift($trace);
|
||||
// We remove at least the first two items from the list since they contain data that we don't need.
|
||||
$trace = array_slice($trace, 2 + $offset);
|
||||
|
||||
$callstack = [];
|
||||
$previous = ['class' => '', 'function' => '', 'database' => false];
|
||||
|
|
|
@ -90,7 +90,7 @@ class Theme
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
$theme_file = file_get_contents("view/theme/$theme/theme.php");
|
||||
DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
|
||||
DI::profiler()->saveTimestamp($stamp1, "file");
|
||||
|
||||
$result = preg_match("|/\*.*\*/|msU", $theme_file, $matches);
|
||||
|
||||
|
@ -158,6 +158,8 @@ class Theme
|
|||
if (function_exists($func)) {
|
||||
$func();
|
||||
}
|
||||
|
||||
Hook::delete(['file' => "view/theme/$theme/theme.php"]);
|
||||
}
|
||||
|
||||
$allowed_themes = Theme::getAllowedList();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue