Merge pull request #8931 from MrPetovan/task/2020-performance-improvements

Various performance improvements
This commit is contained in:
Michael Vogel 2020-07-28 07:15:02 +02:00 committed by GitHub
commit 74bc3de472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 203 additions and 100 deletions

View File

@ -26,6 +26,8 @@ use FastRoute\DataGenerator\GroupCountBased;
use FastRoute\Dispatcher;
use FastRoute\RouteCollector;
use FastRoute\RouteParser\Std;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\ICache;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Network\HTTPException;
@ -66,14 +68,24 @@ class Router
/** @var L10n */
private $l10n;
/** @var ICache */
private $cache;
/** @var string */
private $baseRoutesFilepath;
/**
* @param array $server The $_SERVER variable
* @param L10n $l10n
* @param RouteCollector|null $routeCollector Optional the loaded Route collector
* @param array $server The $_SERVER variable
* @param string $baseRoutesFilepath The path to a base routes file to leverage cache, can be empty
* @param L10n $l10n
* @param ICache $cache
* @param RouteCollector|null $routeCollector
*/
public function __construct(array $server, L10n $l10n, RouteCollector $routeCollector = null)
public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICache $cache, RouteCollector $routeCollector = null)
{
$this->baseRoutesFilepath = $baseRoutesFilepath;
$this->l10n = $l10n;
$this->cache = $cache;
$httpMethod = $server['REQUEST_METHOD'] ?? self::GET;
$this->httpMethod = in_array($httpMethod, self::ALLOWED_METHODS) ? $httpMethod : self::GET;
@ -84,6 +96,9 @@ class Router
}
/**
* This will be called either automatically if a base routes file path was submitted,
* or can be called manually with a custom route array.
*
* @param array $routes The routes to add to the Router
*
* @return self The router instance with the loaded routes
@ -100,6 +115,9 @@ class Router
$this->routeCollector = $routeCollector;
// Add routes from addons
Hook::callAll('route_collection', $this->routeCollector);
return $this;
}
@ -191,12 +209,9 @@ class Router
*/
public function getModuleClass($cmd)
{
// Add routes from addons
Hook::callAll('route_collection', $this->routeCollector);
$cmd = '/' . ltrim($cmd, '/');
$dispatcher = new Dispatcher\GroupCountBased($this->routeCollector->getData());
$dispatcher = new Dispatcher\GroupCountBased($this->getCachedDispatchData());
$moduleClass = null;
$this->parameters = [];
@ -223,4 +238,51 @@ class Router
{
return $this->parameters;
}
/**
* If a base routes file path has been provided, we can load routes from it if the cache misses.
*
* @return array
* @throws HTTPException\InternalServerErrorException
*/
private function getDispatchData()
{
$dispatchData = [];
if ($this->baseRoutesFilepath && file_exists($this->baseRoutesFilepath)) {
$dispatchData = require $this->baseRoutesFilepath;
if (!is_array($dispatchData)) {
throw new HTTPException\InternalServerErrorException('Invalid base routes file');
}
}
$this->loadRoutes($dispatchData);
return $this->routeCollector->getData();
}
/**
* We cache the dispatch data for speed, as computing the current routes (version 2020.09)
* takes about 850ms for each requests.
*
* The cached "routerDispatchData" lasts for a day, and must be cleared manually when there
* is any changes in the enabled addons list.
*
* @return array|mixed
* @throws HTTPException\InternalServerErrorException
*/
private function getCachedDispatchData()
{
$routerDispatchData = $this->cache->get('routerDispatchData');
if ($routerDispatchData) {
return $routerDispatchData;
}
$routerDispatchData = $this->getDispatchData();
$this->cache->set('routerDispatchData', $routerDispatchData, Duration::DAY);
return $routerDispatchData;
}
}

View File

@ -1098,7 +1098,7 @@ class BBCode
@curl_exec($ch);
$curl_info = @curl_getinfo($ch);
DI::profiler()->saveTimestamp($stamp1, "network", System::callstack());
DI::profiler()->saveTimestamp($stamp1, "network");
if (substr($curl_info['content_type'], 0, 6) == 'image/') {
$text = "[url=" . $match[1] . ']' . $match[1] . "[/url]";
@ -1172,7 +1172,7 @@ class BBCode
@curl_exec($ch);
$curl_info = @curl_getinfo($ch);
DI::profiler()->saveTimestamp($stamp1, "network", System::callstack());
DI::profiler()->saveTimestamp($stamp1, "network");
// if its a link to a picture then embed this picture
if (substr($curl_info['content_type'], 0, 6) == 'image/') {
@ -2045,7 +2045,7 @@ class BBCode
// Now convert HTML to Markdown
$text = HTML::toMarkdown($text);
DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack());
DI::profiler()->saveTimestamp($stamp1, "parser");
// Libertree has a problem with escaped hashtags.
$text = str_replace(['\#'], ['#'], $text);

View File

@ -57,7 +57,7 @@ class Markdown
$html = $MarkdownParser->transform($text);
DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack());
DI::profiler()->saveTimestamp($stamp1, "parser");
return $html;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -699,7 +699,7 @@ class Database
$this->errorno = $errorno;
}
$this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'database');
if ($this->configCache->get('system', 'db_log')) {
$stamp2 = microtime(true);
@ -783,7 +783,7 @@ class Database
$this->errorno = $errorno;
}
$this->profiler->saveTimestamp($stamp, "database_write", System::callstack());
$this->profiler->saveTimestamp($stamp, "database_write");
return $retval;
}
@ -964,7 +964,7 @@ class Database
}
}
$this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'database');
return $columns;
}
@ -1644,7 +1644,7 @@ class Database
break;
}
$this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'database');
return $ret;
}

View File

@ -85,7 +85,7 @@ class SessionFactory
$session = new Session\Native($baseURL, $handler);
}
} finally {
$profiler->saveTimestamp($stamp1, 'parser', System::callstack());
$profiler->saveTimestamp($stamp1, 'parser');
return $session;
}
}

View File

@ -199,7 +199,7 @@ class HTTPRequest implements IHTTPRequest
@curl_close($ch);
$this->profiler->saveTimestamp($stamp1, 'network', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'network');
return $curlResponse;
}
@ -285,7 +285,7 @@ class HTTPRequest implements IHTTPRequest
curl_close($ch);
$this->profiler->saveTimestamp($stamp1, 'network', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'network');
// Very old versions of Lighttpd don't like the "Expect" header, so we remove it when needed
if ($curlResponse->getReturnCode() == 417) {
@ -335,7 +335,7 @@ class HTTPRequest implements IHTTPRequest
$http_code = $curl_info['http_code'];
curl_close($ch);
$this->profiler->saveTimestamp($stamp1, "network", System::callstack());
$this->profiler->saveTimestamp($stamp1, "network");
if ($http_code == 0) {
return $url;
@ -377,7 +377,7 @@ class HTTPRequest implements IHTTPRequest
$body = curl_exec($ch);
curl_close($ch);
$this->profiler->saveTimestamp($stamp1, "network", System::callstack());
$this->profiler->saveTimestamp($stamp1, "network");
if (trim($body) == "") {
return $url;

View File

@ -625,7 +625,7 @@ class Image
$stamp1 = microtime(true);
file_put_contents($path, $string);
DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
DI::profiler()->saveTimestamp($stamp1, "file");
}
/**

View File

@ -200,7 +200,7 @@ class Images
$stamp1 = microtime(true);
file_put_contents($tempfile, $img_str);
DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
DI::profiler()->saveTimestamp($stamp1, "file");
$data = getimagesize($tempfile);
unlink($tempfile);

View File

@ -61,7 +61,7 @@ class ProfilerLogger implements LoggerInterface
{
$stamp1 = microtime(true);
$this->logger->emergency($message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'file');
}
/**
@ -71,7 +71,7 @@ class ProfilerLogger implements LoggerInterface
{
$stamp1 = microtime(true);
$this->logger->alert($message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'file');
}
/**
@ -81,7 +81,7 @@ class ProfilerLogger implements LoggerInterface
{
$stamp1 = microtime(true);
$this->logger->critical($message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'file');
}
/**
@ -91,7 +91,7 @@ class ProfilerLogger implements LoggerInterface
{
$stamp1 = microtime(true);
$this->logger->error($message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'file');
}
/**
@ -101,7 +101,7 @@ class ProfilerLogger implements LoggerInterface
{
$stamp1 = microtime(true);
$this->logger->warning($message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'file');
}
/**
@ -111,7 +111,7 @@ class ProfilerLogger implements LoggerInterface
{
$stamp1 = microtime(true);
$this->logger->notice($message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'file');
}
/**
@ -121,7 +121,7 @@ class ProfilerLogger implements LoggerInterface
{
$stamp1 = microtime(true);
$this->logger->info($message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'file');
}
/**
@ -131,7 +131,7 @@ class ProfilerLogger implements LoggerInterface
{
$stamp1 = microtime(true);
$this->logger->debug($message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'file');
}
/**
@ -141,6 +141,6 @@ class ProfilerLogger implements LoggerInterface
{
$stamp1 = microtime(true);
$this->logger->log($level, $message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
$this->profiler->saveTimestamp($stamp1, 'file');
}
}

View File

@ -23,6 +23,7 @@ namespace Friendica\Util;
use Friendica\Core\Config\Cache;
use Friendica\Core\Config\IConfig;
use Friendica\Core\System;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -88,9 +89,9 @@ class Profiler implements ContainerInterface
* Saves a timestamp for a value - f.e. a call
* Necessary for profiling Friendica
*
* @param int $timestamp the Timestamp
* @param string $value A value to profile
* @param string $callstack The callstack of the current profiling data
* @param int $timestamp the Timestamp
* @param string $value A value to profile
* @param string $callstack A callstack string, generated if absent
*/
public function saveTimestamp($timestamp, $value, $callstack = '')
{
@ -98,6 +99,8 @@ class Profiler implements ContainerInterface
return;
}
$callstack = $callstack ?: System::callstack(4, 1);
$duration = floatval(microtime(true) - $timestamp);
if (!isset($this->performance[$value])) {

View File

@ -191,10 +191,9 @@ return [
],
App\Router::class => [
'constructParams' => [
$_SERVER, null
],
'call' => [
['loadRoutes', [include __DIR__ . '/routes.config.php'], Dice::CHAIN_CALL],
$_SERVER,
__DIR__ . '/routes.config.php',
null
],
],
L10n::class => [

View File

@ -22,6 +22,7 @@
namespace Friendica\Test\src\App;
use Friendica\App;
use Friendica\Core\Cache\ICache;
use Friendica\Core\Config\IConfig;
use Friendica\Core\L10n;
use Friendica\LegacyModule;
@ -175,7 +176,11 @@ class ModuleTest extends DatabaseTest
$l10n = \Mockery::mock(L10n::class);
$l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
$router = (new App\Router([], $l10n))->loadRoutes(include __DIR__ . '/../../../static/routes.config.php');
$cache = \Mockery::mock(ICache::class);
$cache->shouldReceive('get')->with('routerDispatchData')->andReturn('')->atMost()->once();
$cache->shouldReceive('set')->withAnyArgs()->andReturn(false)->atMost()->once();
$router = (new App\Router([], __DIR__ . '/../../../static/routes.config.php', $l10n, $cache));
$module = (new App\Module($name))->determineClass(new App\Arguments('', $command), $router, $config);

View File

@ -22,6 +22,7 @@
namespace Friendica\Test\src\App;
use Friendica\App\Router;
use Friendica\Core\Cache\ICache;
use Friendica\Core\L10n;
use Friendica\Module;
use Friendica\Network\HTTPException\MethodNotAllowedException;
@ -33,6 +34,10 @@ class RouterTest extends TestCase
{
/** @var L10n|MockInterface */
private $l10n;
/**
* @var ICache
*/
private $cache;
protected function setUp()
{
@ -40,11 +45,15 @@ class RouterTest extends TestCase
$this->l10n = \Mockery::mock(L10n::class);
$this->l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
$this->cache = \Mockery::mock(ICache::class);
$this->cache->shouldReceive('get')->andReturn(null);
$this->cache->shouldReceive('set')->andReturn(false);
}
public function testGetModuleClass()
{
$router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
$router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::GET], '/', 'IndexModuleClassName');
@ -68,7 +77,7 @@ class RouterTest extends TestCase
public function testPostModuleClass()
{
$router = new Router(['REQUEST_METHOD' => Router::POST], $this->l10n);
$router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::POST], '/', 'IndexModuleClassName');
@ -94,7 +103,7 @@ class RouterTest extends TestCase
{
$this->expectException(NotFoundException::class);
$router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
$router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$router->getModuleClass('/unsupported');
}
@ -103,7 +112,7 @@ class RouterTest extends TestCase
{
$this->expectException(NotFoundException::class);
$router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
$router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName');
@ -115,7 +124,7 @@ class RouterTest extends TestCase
{
$this->expectException(NotFoundException::class);
$router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
$router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::GET], '/optional[/option]', 'OptionalModuleClassName');
@ -127,7 +136,7 @@ class RouterTest extends TestCase
{
$this->expectException(NotFoundException::class);
$router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
$router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::GET], '/variable/{var}', 'VariableModuleClassName');
@ -139,7 +148,7 @@ class RouterTest extends TestCase
{
$this->expectException(MethodNotAllowedException::class);
$router = new Router(['REQUEST_METHOD' => Router::POST], $this->l10n);
$router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName');
@ -151,7 +160,7 @@ class RouterTest extends TestCase
{
$this->expectException(MethodNotAllowedException::class);
$router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
$router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::POST], '/test', 'TestModuleClassName');
@ -189,9 +198,12 @@ class RouterTest extends TestCase
*/
public function testGetRoutes(array $routes)
{
$router = (new Router([
'REQUEST_METHOD' => Router::GET
], $this->l10n))->loadRoutes($routes);
$router = (new Router(
['REQUEST_METHOD' => Router::GET],
'',
$this->l10n,
$this->cache
))->loadRoutes($routes);
$this->assertEquals(Module\Home::class, $router->getModuleClass('/'));
$this->assertEquals(Module\Friendica::class, $router->getModuleClass('/group/route'));
@ -206,7 +218,7 @@ class RouterTest extends TestCase
{
$router = (new Router([
'REQUEST_METHOD' => Router::POST
], $this->l10n))->loadRoutes($routes);
], '', $this->l10n, $this->cache))->loadRoutes($routes);
// Don't find GET
$this->assertEquals(Module\NodeInfo::class, $router->getModuleClass('/post/it'));

View File

@ -58,7 +58,7 @@ class ProfilerLoggerTest extends MockedTest
$logger = new ProfilerLogger($this->logger, $this->profiler);
$this->logger->shouldReceive($function)->with($message, $context)->once();
$this->profiler->shouldReceive('saveTimestamp')->with(\Mockery::any(), 'file', \Mockery::any())->once();
$this->profiler->shouldReceive('saveTimestamp')->with(\Mockery::any(), 'file')->once();
$logger->$function($message, $context);
}
@ -70,7 +70,7 @@ class ProfilerLoggerTest extends MockedTest
$logger = new ProfilerLogger($this->logger, $this->profiler);
$this->logger->shouldReceive('log')->with(LogLevel::WARNING, 'test', ['a' => 'context'])->once();
$this->profiler->shouldReceive('saveTimestamp')->with(\Mockery::any(), 'file', \Mockery::any())->once();
$this->profiler->shouldReceive('saveTimestamp')->with(\Mockery::any(), 'file')->once();
$logger->log(LogLevel::WARNING, 'test', ['a' => 'context']);
}

View File

@ -54,18 +54,6 @@ function frio_install()
Logger::log('installed theme frio');
}
function frio_uninstall()
{
Hook::unregister('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
Hook::unregister('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
Hook::unregister('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
Hook::unregister('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
Hook::unregister('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
Hook::unregister('display_item', 'view/theme/frio/theme.php', 'frio_display_item');
Logger::log('uninstalled theme frio');
}
/**
* Replace friendica photo links hook
*