Browse Source

More sql and page caching

Jordi Boggiano 11 years ago
parent
commit
76da32a84a

+ 4 - 0
src/Packagist/WebBundle/Controller/WebController.php

@@ -36,6 +36,7 @@ use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Symfony\Component\Console\Output\OutputInterface;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
 use Symfony\Component\Security\Core\Exception\AccessDeniedException;
@@ -61,6 +62,7 @@ class WebController extends Controller
     /**
      * @Template("PackagistWebBundle:Web:browse.html.twig")
      * @Route("/packages/", name="allPackages")
+     * @Cache(smaxage=900)
      */
     public function allAction(Request $req)
     {
@@ -124,6 +126,7 @@ class WebController extends Controller
     /**
      * @Template()
      * @Route("/explore/popular", name="browse_popular")
+     * @Cache(smaxage=900)
      */
     public function popularAction(Request $req)
     {
@@ -156,6 +159,7 @@ class WebController extends Controller
     /**
      * @Route("/packages/list.json", name="list", defaults={"_format"="json"})
      * @Method({"GET"})
+     * @Cache(smaxage=60)
      */
     public function listAction(Request $req)
     {

+ 11 - 2
src/Packagist/WebBundle/Entity/PackageRepository.php

@@ -199,8 +199,16 @@ class PackageRepository extends EntityRepository
 
     public function getFilteredQueryBuilder(array $filters = array())
     {
-        $qb = $this->getBaseQueryBuilder()
-            ->select('p', 'v');
+        $qb = $this->getEntityManager()->createQueryBuilder();
+        $qb->select('p')
+            ->from('Packagist\WebBundle\Entity\Package', 'p');
+
+        if (isset($filters['tag'])) {
+            $qb->leftJoin('p.versions', 'v');
+            $qb->leftJoin('v.tags', 't');
+        }
+
+        $qb->orderBy('p.id', 'DESC');
 
         $this->addFilters($qb, $filters);
 
@@ -220,6 +228,7 @@ class PackageRepository extends EntityRepository
                     break;
 
                 case 'maintainer':
+                    $qb->leftJoin('p.maintainers', 'm');
                     $qb->andWhere($qb->expr()->in('m.id', ':'.$name));
                     break;