Skip to content

Commit

Permalink
Merge pull request #3849 from chihiro-adachi/fix-performance
Browse files Browse the repository at this point in the history
パフォーマンスチューニング
  • Loading branch information
okazy authored Sep 14, 2018
2 parents 65284bf + 386547b commit e26dd42
Show file tree
Hide file tree
Showing 21 changed files with 246 additions and 85 deletions.
3 changes: 3 additions & 0 deletions app/config/eccube/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ services:
lazy: true
public: true

Ecccube\Service\CartService:
lazy: true

Eccube\Service\SystemService:
lazy: true
public: true
Expand Down
17 changes: 9 additions & 8 deletions src/Eccube/Controller/Admin/Content/BlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Eccube\Form\Type\Admin\BlockType;
use Eccube\Repository\BlockRepository;
use Eccube\Repository\Master\DeviceTypeRepository;
use Eccube\Util\CacheUtil;
use Eccube\Util\StringUtil;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Filesystem\Filesystem;
Expand Down Expand Up @@ -80,7 +81,7 @@ public function index(Request $request)
* @Route("/%eccube_admin_route%/content/block/{id}/edit", requirements={"id" = "\d+"}, name="admin_content_block_edit")
* @Template("@admin/Content/block_edit.twig")
*/
public function edit(Request $request, $id = null, Environment $twig, FileSystem $fs)
public function edit(Request $request, $id = null, Environment $twig, FileSystem $fs, CacheUtil $cacheUtil)
{
$DeviceType = $this->deviceTypeRepository
->find(DeviceType::DEVICE_TYPE_PC);
Expand Down Expand Up @@ -153,9 +154,9 @@ public function edit(Request $request, $id = null, Environment $twig, FileSystem
}
}

// twigキャッシュの削除
$cacheDir = $this->getParameter('kernel.cache_dir').'/twig';
$fs->remove($cacheDir);
// キャッシュの削除
$cacheUtil->clearTwigCache();
$cacheUtil->clearDoctrineCache();

$event = new EventArgs(
[
Expand All @@ -181,7 +182,7 @@ public function edit(Request $request, $id = null, Environment $twig, FileSystem
/**
* @Route("/%eccube_admin_route%/content/block/{id}/delete", requirements={"id" = "\d+"}, name="admin_content_block_delete", methods={"DELETE"})
*/
public function delete(Request $request, Block $Block, Filesystem $fs)
public function delete(Request $request, Block $Block, Filesystem $fs, CacheUtil $cacheUtil)
{
$this->isTokenValid();

Expand Down Expand Up @@ -210,9 +211,9 @@ public function delete(Request $request, Block $Block, Filesystem $fs)

$this->addSuccess('admin.common.delete_complete', 'admin');

// twigキャッシュの削除
$cacheDir = $this->getParameter('kernel.cache_dir').'/twig';
$fs->remove($cacheDir);
// キャッシュの削除
$cacheUtil->clearTwigCache();
$cacheUtil->clearDoctrineCache();
}

return $this->redirectToRoute('admin_content_block');
Expand Down
15 changes: 11 additions & 4 deletions src/Eccube/Controller/Admin/Content/LayoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Eccube\Repository\PageRepository;
use Eccube\Repository\ProductRepository;
use Eccube\Repository\Master\DeviceTypeRepository;
use Eccube\Util\CacheUtil;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -123,7 +124,7 @@ public function index()
*
* @return RedirectResponse
*/
public function delete(Layout $Layout)
public function delete(Layout $Layout, CacheUtil $cacheUtil)
{
$this->isTokenValid();

Expand All @@ -139,6 +140,9 @@ public function delete(Layout $Layout)

$this->addSuccess('admin.common.delete_complete', 'admin');

// キャッシュの削除
$cacheUtil->clearDoctrineCache();

return $this->redirectToRoute('admin_content_layout');
}

Expand All @@ -147,7 +151,7 @@ public function delete(Layout $Layout)
* @Route("/%eccube_admin_route%/content/layout/{id}/edit", requirements={"id" = "\d+"}, name="admin_content_layout_edit")
* @Template("@admin/Content/layout.twig")
*/
public function edit(Request $request, $id = null, $previewPageId = null)
public function edit(Request $request, $id = null, $previewPageId = null, CacheUtil $cacheUtil)
{
if (is_null($id)) {
$Layout = new Layout();
Expand Down Expand Up @@ -190,6 +194,9 @@ public function edit(Request $request, $id = null, $previewPageId = null)
$data = $request->request->all();
$this->blockPositionRepository->register($data, $Blocks, $UnusedBlocks, $Layout);

// キャッシュの削除
$cacheUtil->clearDoctrineCache();

// プレビューモード
if ($this->isPreview) {
// プレビューする画面を取得
Expand Down Expand Up @@ -266,11 +273,11 @@ public function viewBlock(Request $request, Twig $twig)
/**
* @Route("/%eccube_admin_route%/content/layout/{id}/preview", requirements={"id" = "\d+"}, name="admin_content_layout_preview")
*/
public function preview(Request $request, $id)
public function preview(Request $request, $id, CacheUtil $cacheUtil)
{
$form = $request->get('admin_layout');
$this->isPreview = true;

return $this->edit($request, $id, $form['Page']);
return $this->edit($request, $id, $form['Page'], $cacheUtil);
}
}
12 changes: 10 additions & 2 deletions src/Eccube/Controller/Admin/Content/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Eccube\Event\EventArgs;
use Eccube\Form\Type\Admin\NewsType;
use Eccube\Repository\NewsRepository;
use Eccube\Util\CacheUtil;
use Knp\Component\Pager\Paginator;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -90,7 +91,7 @@ public function index(Request $request, $page_no = 1, Paginator $paginator)
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
*/
public function edit(Request $request, $id = null)
public function edit(Request $request, $id = null, CacheUtil $cacheUtil)
{
if ($id) {
$News = $this->newsRepository->find($id);
Expand Down Expand Up @@ -134,6 +135,9 @@ public function edit(Request $request, $id = null)

$this->addSuccess('admin.common.save_complete', 'admin');

// キャッシュの削除
$cacheUtil->clearDoctrineCache();

return $this->redirectToRoute('admin_content_news_edit', ['id' => $News->getId()]);
}

Expand All @@ -153,7 +157,7 @@ public function edit(Request $request, $id = null)
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function delete(Request $request, News $News)
public function delete(Request $request, News $News, CacheUtil $cacheUtil)
{
$this->isTokenValid();

Expand All @@ -168,6 +172,10 @@ public function delete(Request $request, News $News)
$this->addSuccess('admin.common.delete_complete', 'admin');

log_info('新着情報削除完了', [$News->getId()]);

// キャッシュの削除
$cacheUtil->clearDoctrineCache();

} catch (\Exception $e) {
$message = trans('admin.common.delete_error_foreign_key', ['%name%' => $News->getTitle()]);
$this->addError($message, 'admin');
Expand Down
16 changes: 11 additions & 5 deletions src/Eccube/Controller/Admin/Content/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
use Eccube\Repository\Master\DeviceTypeRepository;
use Eccube\Repository\PageLayoutRepository;
use Eccube\Repository\PageRepository;
use Eccube\Util\CacheUtil;
use Eccube\Util\StringUtil;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;

class PageController extends AbstractController
Expand Down Expand Up @@ -89,7 +91,7 @@ public function index(Request $request)
* @Route("/%eccube_admin_route%/content/page/{id}/edit", requirements={"id" = "\d+"}, name="admin_content_page_edit")
* @Template("@admin/Content/page_edit.twig")
*/
public function edit(Request $request, $id = null, Environment $twig, Router $router)
public function edit(Request $request, $id = null, Environment $twig, RouterInterface $router, CacheUtil $cacheUtil)
{
if (null === $id) {
$Page = $this->pageRepository->newPage();
Expand Down Expand Up @@ -222,9 +224,9 @@ public function edit(Request $request, $id = null, Environment $twig, Router $ro

$this->addSuccess('admin.common.save_complete', 'admin');

// twig キャッシュの削除.
$cacheDir = $this->getParameter('kernel.cache_dir').'/twig';
$fs->remove($cacheDir);
// キャッシュの削除
$cacheUtil->clearTwigCache();
$cacheUtil->clearDoctrineCache();

return $this->redirectToRoute('admin_content_page_edit', ['id' => $Page->getId()]);
}
Expand All @@ -251,7 +253,7 @@ public function edit(Request $request, $id = null, Environment $twig, Router $ro
/**
* @Route("/%eccube_admin_route%/content/page/{id}/delete", requirements={"id" = "\d+"}, name="admin_content_page_delete", methods={"DELETE"})
*/
public function delete(Request $request, $id = null)
public function delete(Request $request, $id = null, CacheUtil $cacheUtil)
{
$this->isTokenValid();

Expand Down Expand Up @@ -286,6 +288,10 @@ public function delete(Request $request, $id = null)
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CONTENT_PAGE_DELETE_COMPLETE, $event);

$this->addSuccess('admin.common.delete_complete', 'admin');

// キャッシュの削除
$cacheUtil->clearTwigCache();
$cacheUtil->clearDoctrineCache();
}

return $this->redirectToRoute('admin_content_page');
Expand Down
17 changes: 14 additions & 3 deletions src/Eccube/Controller/Admin/Product/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Eccube\Form\Type\Admin\CategoryType;
use Eccube\Repository\CategoryRepository;
use Eccube\Service\CsvExportService;
use Eccube\Util\CacheUtil;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function __construct(
* @Route("/%eccube_admin_route%/product/category/{id}/edit", requirements={"id" = "\d+"}, name="admin_product_category_edit")
* @Template("@admin/Product/category.twig")
*/
public function index(Request $request, $parent_id = null, $id = null)
public function index(Request $request, $parent_id = null, $id = null, CacheUtil $cacheUtil)
{
if ($parent_id) {
/** @var Category $Parent */
Expand Down Expand Up @@ -137,6 +138,9 @@ public function index(Request $request, $parent_id = null, $id = null)
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_CATEGORY_INDEX_COMPLETE, $event);

$this->addSuccess('admin.common.save_complete', 'admin');

$cacheUtil->clearDoctrineCache();

if ($Parent) {
return $this->redirectToRoute('admin_product_category_show', ['parent_id' => $Parent->getId()]);
} else {
Expand All @@ -162,6 +166,8 @@ public function index(Request $request, $parent_id = null, $id = null)

$this->addSuccess('admin.common.save_complete', 'admin');

$cacheUtil->clearDoctrineCache();

if ($Parent) {
return $this->redirectToRoute('admin_product_category_show', ['parent_id' => $Parent->getId()]);
} else {
Expand Down Expand Up @@ -198,7 +204,7 @@ public function index(Request $request, $parent_id = null, $id = null)
/**
* @Route("/%eccube_admin_route%/product/category/{id}/delete", requirements={"id" = "\d+"}, name="admin_product_category_delete", methods={"DELETE"})
*/
public function delete(Request $request, $id)
public function delete(Request $request, $id, CacheUtil $cacheUtil)
{
$this->isTokenValid();

Expand Down Expand Up @@ -226,6 +232,9 @@ public function delete(Request $request, $id)
$this->addSuccess('admin.common.delete_complete', 'admin');

log_info('カテゴリ削除完了', [$id]);

$cacheUtil->clearDoctrineCache();

} catch (\Exception $e) {
log_info('カテゴリ削除エラー', [$id, $e]);

Expand All @@ -243,7 +252,7 @@ public function delete(Request $request, $id)
/**
* @Route("/%eccube_admin_route%/product/category/sort_no/move", name="admin_product_category_sort_no_move", methods={"POST"})
*/
public function moveSortNo(Request $request)
public function moveSortNo(Request $request, CacheUtil $cacheUtil)
{
if (!$request->isXmlHttpRequest()) {
throw new BadRequestHttpException();
Expand All @@ -260,6 +269,8 @@ public function moveSortNo(Request $request)
}
$this->entityManager->flush();

$cacheUtil->clearDoctrineCache();

return new Response('Successful');
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Eccube/Controller/Admin/Product/CsvImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Eccube\Repository\ProductRepository;
use Eccube\Repository\TagRepository;
use Eccube\Service\CsvImportService;
use Eccube\Util\CacheUtil;
use Eccube\Util\StringUtil;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Filesystem\Filesystem;
Expand Down Expand Up @@ -538,7 +539,7 @@ public function csvProduct(Request $request)
* @Route("/%eccube_admin_route%/product/category_csv_upload", name="admin_product_category_csv_import")
* @Template("@admin/Product/csv_category.twig")
*/
public function csvCategory(Request $request)
public function csvCategory(Request $request, CacheUtil $cacheUtil)
{
$form = $this->formFactory->createBuilder(CsvImportType::class)->getForm();

Expand Down Expand Up @@ -683,6 +684,8 @@ public function csvCategory(Request $request)
log_info('カテゴリCSV登録完了');
$message = 'admin.common.csv_upload_complete';
$this->session->getFlashBag()->add('eccube.admin.success', $message);

$cacheUtil->clearDoctrineCache();
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Eccube/Controller/Admin/Setting/Shop/ShopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function index(Request $request, CacheUtil $cacheUtil)
$event
);

$cacheUtil->clearCache();
// キャッシュの削除
$cacheUtil->clearDoctrineCache();

$this->addSuccess('admin.common.save_complete', 'admin');

Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Entity/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity(repositoryClass="Eccube\Repository\NewsRepository")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
*/
class News extends AbstractEntity
{
Expand Down
30 changes: 12 additions & 18 deletions src/Eccube/EventListener/TwigInitializeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,7 @@ public function setFrontVariables(GetResponseEvent $event)

// URLからPageを取得
/** @var Page $Page */
$Page = $this->pageRepository->findOneBy(['url' => $route]);

// 該当するPageがない場合は空のページをセット
if (!$Page) {
$Page = $this->pageRepository->newPage();
}
$Page = $this->pageRepository->getPageByRoute($route);

/** @var PageLayout[] $PageLayouts */
$PageLayouts = $Page->getPageLayouts();
Expand Down Expand Up @@ -227,22 +222,21 @@ public function setFrontVariables(GetResponseEvent $event)
if ($request->get('preview')) {
$is_admin = $request->getSession()->has('_security_admin');
if ($is_admin) {
$Page->getPageLayouts()->clear();
$PageLayouts = $this->pageLayoutRepository->findBy(['layout_id' => 0]);
foreach ($PageLayouts as $PageLayout) {
$Page->addPageLayout($PageLayout);
}
$Layout = $this->layoutRepository->get(Layout::DEFAULT_LAYOUT_PREVIEW_PAGE);

$Layout->getBlockPositions()->clear();
$BlockPositions = $this->blockPositionRepository->findBy(['layout_id' => 0]);
foreach ($BlockPositions as $BlockPosition) {
$Layout->addBlockPosition($BlockPosition);
}
$this->twig->addGlobal('Layout', $Layout);
$this->twig->addGlobal('Page', $Page);
$this->twig->addGlobal('title', $Page->getName());

return;
}
}

// Layoutのデータがない場合は空のLayoutをセット
if (!$Layout) {
if ($Layout) {
// lazy loadを制御するため, Layoutを取得しなおす.
$Layout = $this->layoutRepository->get($Layout->getId());
} else {
// Layoutのデータがない場合は空のLayoutをセット
$Layout = new Layout();
}

Expand Down
Loading

0 comments on commit e26dd42

Please sign in to comment.