Sort by id is faster

Since it's the primary key
This commit is contained in:
Jeremy 2015-03-28 14:28:24 +01:00
parent 0c83fd5994
commit 2385f891e5

View file

@ -26,7 +26,7 @@ class EntryRepository extends EntityRepository
->leftJoin('e.user', 'u') ->leftJoin('e.user', 'u')
->where('e.isArchived = false') ->where('e.isArchived = false')
->andWhere('u.id =:userId')->setParameter('userId', $userId) ->andWhere('u.id =:userId')->setParameter('userId', $userId)
->orderBy('e.createdAt', 'desc') ->orderBy('e.id', 'desc')
->getQuery(); ->getQuery();
$paginator = new Paginator($qb); $paginator = new Paginator($qb);
@ -52,7 +52,7 @@ class EntryRepository extends EntityRepository
->leftJoin('e.user', 'u') ->leftJoin('e.user', 'u')
->where('e.isArchived = true') ->where('e.isArchived = true')
->andWhere('u.id =:userId')->setParameter('userId', $userId) ->andWhere('u.id =:userId')->setParameter('userId', $userId)
->orderBy('e.createdAt', 'desc') ->orderBy('e.id', 'desc')
->getQuery(); ->getQuery();
$paginator = new Paginator($qb); $paginator = new Paginator($qb);
@ -78,7 +78,7 @@ class EntryRepository extends EntityRepository
->leftJoin('e.user', 'u') ->leftJoin('e.user', 'u')
->where('e.isStarred = true') ->where('e.isStarred = true')
->andWhere('u.id =:userId')->setParameter('userId', $userId) ->andWhere('u.id =:userId')->setParameter('userId', $userId)
->orderBy('e.createdAt', 'desc') ->orderBy('e.id', 'desc')
->getQuery(); ->getQuery();
$paginator = new Paginator($qb); $paginator = new Paginator($qb);
@ -111,7 +111,7 @@ class EntryRepository extends EntityRepository
} }
if ('created' === $sort) { if ('created' === $sort) {
$qb->orderBy('e.createdAt', $order); $qb->orderBy('e.id', $order);
} elseif ('updated' === $sort) { } elseif ('updated' === $sort) {
$qb->orderBy('e.updatedAt', $order); $qb->orderBy('e.updatedAt', $order);
} }