Created
October 5, 2016 09:57
-
-
Save nanasess/ece7de62298dea3a9924cd13da8519eb to your computer and use it in GitHub Desktop.
プラグインロードの時間計測
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Eccube/Application.php b/src/Eccube/Application.php | |
index a32eb1b..f6f103a 100644 | |
--- a/src/Eccube/Application.php | |
+++ b/src/Eccube/Application.php | |
@@ -114,17 +114,27 @@ class Application extends ApplicationTrait | |
return; | |
} | |
+ $start = microtime(true); | |
// init locale | |
$this->initLocale(); | |
+ $end = microtime(true); | |
+ echo 'initLocale: '.($end - $start).PHP_EOL; | |
+ $start = microtime(true); | |
// init session | |
if (!$this->isSessionStarted()) { | |
$this->initSession(); | |
} | |
+ $end = microtime(true); | |
+ echo 'initSession: '.($end - $start).PHP_EOL; | |
+ $start = microtime(true); | |
// init twig | |
$this->initRendering(); | |
+ $end = microtime(true); | |
+ echo 'initRendering: '.($end - $start).PHP_EOL; | |
+ $start = microtime(true); | |
// init provider | |
$this->register(new \Silex\Provider\HttpCacheServiceProvider(), array( | |
'http_cache.cache_dir' => __DIR__.'/../../app/cache/http/', | |
@@ -134,6 +144,8 @@ class Application extends ApplicationTrait | |
$this->register(new \Silex\Provider\FormServiceProvider()); | |
$this->register(new \Silex\Provider\SerializerServiceProvider()); | |
$this->register(new \Eccube\ServiceProvider\ValidatorServiceProvider()); | |
+ $end = microtime(true); | |
+ echo 'initProvider: '.($end - $start).PHP_EOL; | |
$app = $this; | |
$this->error(function (\Exception $e, $code) use ($app) { | |
@@ -162,18 +174,28 @@ class Application extends ApplicationTrait | |
)); | |
}); | |
+ $start = microtime(true); | |
// init mailer | |
$this->initMailer(); | |
+ $end = microtime(true); | |
+ echo 'initMailer: '.($end - $start).PHP_EOL; | |
+ $start = microtime(true); | |
// init doctrine orm | |
$this->initDoctrine(); | |
+ $end = microtime(true); | |
+ echo 'initDoctrine: '.($end - $start).PHP_EOL; | |
// Set up the DBAL connection now to check for a proper connection to the database. | |
$this->checkDatabaseConnection(); | |
+ $start = microtime(true); | |
// init security | |
$this->initSecurity(); | |
+ $end = microtime(true); | |
+ echo 'initSecurity: '.($end - $start).PHP_EOL; | |
+ $start = microtime(true); | |
// init ec-cube service provider | |
$this->register(new ServiceProvider\EccubeServiceProvider()); | |
@@ -182,6 +204,8 @@ class Application extends ApplicationTrait | |
$this->mount('', new ControllerProvider\FrontControllerProvider()); | |
$this->mount('/'.trim($this['config']['admin_route'], '/').'/', new ControllerProvider\AdminControllerProvider()); | |
Request::enableHttpMethodParameterOverride(); // PUTやDELETEできるようにする | |
+ $end = microtime(true); | |
+ echo 'initServiceProvider: '.($end - $start).PHP_EOL; | |
// add transaction listener | |
$this['dispatcher']->addSubscriber(new TransactionListener($this)); | |
@@ -415,7 +439,7 @@ class Application extends ApplicationTrait | |
->in($pluginBasePath) | |
->directories() | |
->depth(0); | |
- | |
+ // $finder = array(); | |
$ormMappings = array(); | |
$ormMappings[] = array( | |
'type' => 'yml', | |
@@ -822,18 +846,22 @@ class Application extends ApplicationTrait | |
{ | |
// プラグインディレクトリを探索. | |
$basePath = __DIR__.'/../../app/Plugin'; | |
+ $start = microtime(true); | |
$finder = Finder::create() | |
->in($basePath) | |
->directories() | |
->depth(0); | |
- | |
$finder->sortByName(); | |
+ $end = microtime(true); | |
+ echo 'finder: '.($end - $start).PHP_EOL; | |
// ハンドラ優先順位をdbから持ってきてハッシュテーブルを作成 | |
+ $start = microtime(true); | |
$priorities = array(); | |
- $handlers = $this['orm.em'] | |
- ->getRepository('Eccube\Entity\PluginEventHandler') | |
- ->getHandlers(); | |
+ $Repository = $this['orm.em']->getRepository('Eccube\Entity\PluginEventHandler'); | |
+ $handlers = $Repository->getHandlers(); | |
+ $end = microtime(true); | |
+ echo 'handler: '.($end - $start).PHP_EOL; | |
foreach ($handlers as $handler) { | |
if ($handler->getPlugin()->getEnable() && !$handler->getPlugin()->getDelFlg()) { | |
@@ -845,8 +873,10 @@ class Application extends ApplicationTrait | |
$priorities[$handler->getPlugin()->getClassName()][$handler->getEvent()][$handler->getHandler()] = $priority; | |
} | |
+ | |
// プラグインをロードする. | |
// config.yml/event.ymlの定義に沿ってインスタンスの生成を行い, イベント設定を行う. | |
+ $start = microtime(true); | |
foreach ($finder as $dir) { | |
//config.ymlのないディレクトリは無視する | |
$path = $dir->getRealPath(); | |
@@ -879,7 +909,7 @@ class Application extends ApplicationTrait | |
if ($plugin && $plugin->getEnable() == Constant::DISABLED) { | |
// プラグインが無効化されていれば読み込まない | |
- continue; | |
+ // continue; | |
} | |
// Type: Event | |
@@ -927,6 +957,8 @@ class Application extends ApplicationTrait | |
} | |
} | |
} | |
+ $end = microtime(true); | |
+ echo 'load: '.($end - $start).PHP_EOL; | |
} | |
/** | |
diff --git a/src/Eccube/Repository/PluginEventHandlerRepository.php b/src/Eccube/Repository/PluginEventHandlerRepository.php | |
index 168fce4..90107f6 100644 | |
--- a/src/Eccube/Repository/PluginEventHandlerRepository.php | |
+++ b/src/Eccube/Repository/PluginEventHandlerRepository.php | |
@@ -41,12 +41,13 @@ class PluginEventHandlerRepository extends EntityRepository | |
{ | |
$qb = $this->createQueryBuilder('e') | |
->innerJoin('e.Plugin', 'p') | |
- ->andWhere('e.del_flg = 0 ') | |
- ->Orderby('e.event','ASC') | |
+ ->andWhere('e.del_flg = 0 ') | |
+ ->Orderby('e.event','ASC') | |
->addOrderby('e.priority','DESC'); | |
- ; | |
- | |
- return $qb->getQuery()->getResult(); | |
+ $query = $qb->getQuery(); | |
+ $query->useResultCache(true); | |
+ $query->setResultCacheLifetime(3600); | |
+ return $query->getResult(); | |
} | |
public function getPriorityRange($type) | |
@@ -97,7 +98,7 @@ class PluginEventHandlerRepository extends EntityRepository | |
$qb->andWhere("e.priority >= $range_end ") | |
->andWhere("e.priority <= $range_start ") | |
- ->andWhere("e.del_flg = 0 ") | |
+ ->andWhere("e.del_flg = 0 ") | |
->andWhere('e.priority '.($up ? '>' : '<' ).' :pri') | |
->andWhere('e.event = :event') | |
->setParameter('event',$pluginEventHandler->getEvent()) | |
diff --git a/src/Eccube/Service/PluginService.php b/src/Eccube/Service/PluginService.php | |
index 16e96e9..d127be0 100644 | |
--- a/src/Eccube/Service/PluginService.php | |
+++ b/src/Eccube/Service/PluginService.php | |
@@ -261,12 +261,12 @@ class PluginService | |
public function uninstall(\Eccube\Entity\Plugin $plugin) | |
{ | |
- $pluginDir = $this->calcPluginDir($plugin->getCode()); | |
+ // $pluginDir = $this->calcPluginDir($plugin->getCode()); | |
- $this->callPluginManagerMethod(Yaml::parse(file_get_contents($pluginDir.'/'.self::CONFIG_YML)), 'disable'); | |
- $this->callPluginManagerMethod(Yaml::parse(file_get_contents($pluginDir.'/'.self::CONFIG_YML)), 'uninstall'); | |
- $this->unregisterPlugin($plugin); | |
- $this->deleteFile($pluginDir); | |
+ // $this->callPluginManagerMethod(Yaml::parse(file_get_contents($pluginDir.'/'.self::CONFIG_YML)), 'disable'); | |
+ // $this->callPluginManagerMethod(Yaml::parse(file_get_contents($pluginDir.'/'.self::CONFIG_YML)), 'uninstall'); | |
+ // $this->unregisterPlugin($plugin); | |
+ // $this->deleteFile($pluginDir); | |
return true; | |
} | |
@@ -294,7 +294,8 @@ class PluginService | |
public function disable(\Eccube\Entity\Plugin $plugin) | |
{ | |
- return $this->enable($plugin, false); | |
+ // return $this->enable($plugin, false); | |
+ return true; | |
} | |
public function enable(\Eccube\Entity\Plugin $plugin, $enable = true) | |
diff --git a/tests/Eccube/Tests/EccubeTestCase.php b/tests/Eccube/Tests/EccubeTestCase.php | |
index 87a0168..8b6d2be 100644 | |
--- a/tests/Eccube/Tests/EccubeTestCase.php | |
+++ b/tests/Eccube/Tests/EccubeTestCase.php | |
@@ -256,10 +256,19 @@ abstract class EccubeTestCase extends WebTestCase | |
*/ | |
public function createApplication() | |
{ | |
+ // $start = microtime(true); | |
$app = Application::getInstance(); | |
+ // $end = microtime(true); | |
+ // echo 'get instance: '.($end - $start).PHP_EOL; | |
$app['debug'] = true; | |
+ $start = microtime(true); | |
$app->initialize(); | |
+ $end = microtime(true); | |
+ echo 'initialize: '.($end - $start).PHP_EOL; | |
+ // $start = microtime(true); | |
$app->initializePlugin(); | |
+ // $end = microtime(true); | |
+ // echo 'initialize plugin: '.($end - $start).PHP_EOL; | |
$app['session.test'] = true; | |
$app['exception_handler']->disable(); | |
diff --git a/tests/Eccube/Tests/Service/PluginServiceTest.php b/tests/Eccube/Tests/Service/PluginServiceTest.php | |
index c6f97d4..ea39f19 100644 | |
--- a/tests/Eccube/Tests/Service/PluginServiceTest.php | |
+++ b/tests/Eccube/Tests/Service/PluginServiceTest.php | |
@@ -46,9 +46,11 @@ class PluginServiceTest extends AbstractServiceTestCase | |
} | |
foreach ($dirs as $dir) { | |
- $this->deleteFile($dir); | |
+ // $this->deleteFile($dir); | |
} | |
- parent::tearDown(); | |
+ // parent::tearDown(); | |
+ $this->app['orm.em']->getConnection()->commit(); | |
+ // $this->app['orm.em']->getConnection()->close(); | |
} | |
/* | |
@@ -78,6 +80,7 @@ class PluginServiceTest extends AbstractServiceTestCase | |
// 必要最小限のファイルのプラグインのインストールとアンインストールを検証 | |
public function testInstallPluginMinimum() | |
{ | |
+ // $this->markTestSkipped('skip'); | |
// インストールするプラグインを作成する | |
$tmpname="dummy".sha1(mt_rand()); | |
$config=array(); | |
@@ -115,6 +118,7 @@ class PluginServiceTest extends AbstractServiceTestCase | |
// 必須ファイルがないプラグインがインストール出来ないこと | |
public function testInstallPluginEmptyError() | |
{ | |
+ // $this->markTestSkipped('skip'); | |
$this->setExpectedException( | |
'\Eccube\Exception\PluginException', 'config.yml not found or syntax error' | |
); | |
@@ -135,6 +139,7 @@ class PluginServiceTest extends AbstractServiceTestCase | |
// config.ymlのフォーマット確認 | |
public function testConfigYmlFormat() | |
{ | |
+ // $this->markTestSkipped('skip'); | |
$service = $this->app['eccube.service.plugin']; | |
$tmpname='dummy'.mt_rand(); | |
$tmpfile=sys_get_temp_dir().'/dummy'.mt_rand(); | |
@@ -218,6 +223,7 @@ class PluginServiceTest extends AbstractServiceTestCase | |
// config.ymlに異常な項目がある場合 | |
public function testnstallPluginMalformedConfigError() | |
{ | |
+ // $this->markTestSkipped('skip'); | |
$service = $this->app['eccube.service.plugin']; | |
$tmpdir=$this->createTempDir(); | |
$tmpfile=$tmpdir.'/plugin.tar'; | |
@@ -240,6 +246,7 @@ class PluginServiceTest extends AbstractServiceTestCase | |
// イベント定義を含むプラグインのインストールとアンインストールを検証 | |
public function testInstallPluginWithEvent() | |
{ | |
+ // $this->markTestSkipped('skip'); | |
// インストールするプラグインを作成する | |
$tmpname="dummy".sha1(mt_rand()); | |
$config=array(); | |
@@ -396,15 +403,16 @@ EOD; | |
// アンインストールできるか | |
$this->assertTrue($service->uninstall($plugin)); | |
// ちゃんとファイルが消えているか | |
- $this->assertFalse((boolean)$rep->findOneBy(array('name'=>$tmpname,'enable'=>1))); | |
- $this->assertFileNotExists(__DIR__."/../../../../app/Plugin/$tmpname/config.yml"); | |
- $this->assertFileNotExists(__DIR__."/../../../../app/Plugin/$tmpname/event.yml"); | |
- $this->assertFileNotExists(__DIR__."/../../../../app/Plugin/$tmpname/DummyEvent.php"); | |
+ // $this->assertFalse((boolean)$rep->findOneBy(array('name'=>$tmpname,'enable'=>1))); | |
+ // $this->assertFileNotExists(__DIR__."/../../../../app/Plugin/$tmpname/config.yml"); | |
+ // $this->assertFileNotExists(__DIR__."/../../../../app/Plugin/$tmpname/event.yml"); | |
+ // $this->assertFileNotExists(__DIR__."/../../../../app/Plugin/$tmpname/DummyEvent.php"); | |
} | |
// インストーラが例外を上げた場合ロールバックできるか | |
public function testInstallPluginWithBrokenManagerAfterInstall() | |
{ | |
+ $this->markTestSkipped('skip'); | |
// インストールするプラグインを作成する | |
$tmpname="dummy".sha1(mt_rand()); | |
$config=array(); | |
@@ -468,6 +476,7 @@ EOD; | |
// インストーラを含むプラグインが正しくインストールできるか | |
public function testInstallPluginWithManager() | |
{ | |
+ $this->markTestSkipped('skip'); | |
// インストールするプラグインを作成する | |
$tmpname="dummy".sha1(mt_rand()); | |
$config=array(); | |
@@ -530,16 +539,16 @@ EOD; | |
ob_start(); | |
$service->enable($plugin); | |
$this->assertRegexp('/Enabled/',ob_get_contents()); ob_end_clean(); | |
- ob_start(); | |
- $service->disable($plugin); | |
- $this->assertRegexp('/Disabled/',ob_get_contents()); ob_end_clean(); | |
+ // ob_start(); | |
+ // $service->disable($plugin); | |
+ // $this->assertRegexp('/Disabled/',ob_get_contents()); ob_end_clean(); | |
- // アンインストールできるか、アンインストーラが呼ばれるか | |
- ob_start(); | |
- $service->disable($plugin); | |
- $this->assertTrue($service->uninstall($plugin)); | |
- $this->assertRegexp('/DisabledUninstalled/',ob_get_contents()); ob_end_clean(); | |
+ // // アンインストールできるか、アンインストーラが呼ばれるか | |
+ // ob_start(); | |
+ // $service->disable($plugin); | |
+ // $this->assertTrue($service->uninstall($plugin)); | |
+ // $this->assertRegexp('/DisabledUninstalled/',ob_get_contents()); ob_end_clean(); | |
} | |
@@ -547,6 +556,7 @@ EOD; | |
// const定義を含むpluginのインストール | |
public function testInstallPluginWithConst() | |
{ | |
+ $this->markTestSkipped('skip'); | |
// インストールするプラグインを作成する | |
$tmpname="dummy".sha1(mt_rand()); | |
$config=array(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment