Doctrineアカンパターン

>100 Views

March 26, 15

スライド概要

社内勉強会向け

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

Doctrine アカンパターン RW社内勉強会 3月 岡本秀高

2.

アカンパターン 日本語訳:アンチパターン 要は「やったらアカンこと」 「先人の失敗」に学ぼう

3.

“ 愚者は経験に学び、 賢者は歴史に学ぶ。 オットー・フォン・ビスマルク ” Fools say they learn from experience; I prefer to learn from the experience of others. http://ja.wikiquote.org/wiki/オットー・フォン・ビスマルク

4.

今回の アカンやつ

5.

$result = $this->backend->getEM() ->getRepository('Entities\Item\Item') ->findBy(array('owner_no' => $owner_no) ); return count($result);

6.

$result = $this->backend->getEM() ->getRepository('Entities\Item\Item') ->findBy(array('owner_no' => $owner_no) ); return count($result);

7.

countのためだけに 商品情報を全取得

8.

測ってみた $result = $this->backend->getEM() ->getRepository('Entities\Item\Item') >findBy(array('owner_no' => $owner_no)  1商品につき0.0012秒  160商品で0.35秒  4750商品で 6.13秒 ); 処理落ち  ID:zagzagで return count($result);  _(:3」∠)_

9.

データを数える だけならSQLで!

10.

$em = $this->backend->getEM(); $expr = $em->createQueryBuilder()->expr(); $qb = $em->createQueryBuilder(); $amountItems = $qb->select('count(p)') ->from('Entities\Item\Item', 'p') ->where($expr->eq('p.owner_no', '?1')) ->setParameter(1, $owner_no) ->getQuery() ->getSingleScalarResult(); return $amountItems;

11.

$em = $this->backend->getEM(); $expr = $em->createQueryBuilder()->expr(); $qb = $em->createQueryBuilder(); $amountItems = $qb->select('count(p)') ->from('Entities\Item\Item', 'p') ->where($expr->eq('p.owner_no', '?1')) ->setParameter(1, $owner_no) ->getQuery() ->getSingleScalarResult(); return $amountItems;

12.

速度比較 PHPで数えた場合 SQLで数えた場合  1商品につき0.0012秒  1商品につき0.000000454秒  160商品で0.35秒  160商品で0.000072秒 6.13秒  4750商品で 0.00216秒  4750商品で

13.

速度比較 PHPで数えた場合 SQLで数えた場合  1商品につき0.0012秒  1商品につき0.000000454秒  160商品で0.35秒  160商品で0.000072秒 6.13秒 0.00216秒  4750商品で  4750商品で _(:3」∠)_ (☝ ՞ਊ ՞)☝

14.

使おう、 QueryBuilder

15.

TRY IT!╭( ・ㅂ・)‫̑̑ و‬  15. The QueryBuilder — Doctrine 2 ORM 2 documentation : http://doctrine-orm.readthedocs.org/en/latest/reference/query-builder.html  COUNT関数 - MySQL関数の使い方 - MySQLの使い方 : http://www.dbonline.jp/mysql/function/index6.html  6章 - データを扱う- Symfony : http://symfony.com/legacy/doc/doctrine/1_2/ja/06-working-with-dataA