Last user subscribers events query optimized.

This commit is contained in:
Alexey Skobkin 2015-06-26 19:16:14 +03:00
parent 57cedf5417
commit c5f63d86cb
2 changed files with 4 additions and 3 deletions

View file

@ -30,7 +30,7 @@ class UserController extends Controller
return $this->render('SkobkinPointToolsBundle:User:show.html.twig', [
'user' => $user,
'subscribers' => $em->getRepository('SkobkinPointToolsBundle:User')->findUserSubscribersById($user->getId()),
'log' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getUserLastSubscriptionEventsById($user, 10),
'log' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getUserLastSubscribersEventsById($user, 10),
'avatar_url' => $userApi->getAvatarUrl($user, UserApi::AVATAR_SIZE_LARGE),
]);
}

View file

@ -29,7 +29,7 @@ class SubscriptionEventRepository extends EntityRepository
* @param integer $limit
* @return SubscriptionEvent[]
*/
public function getUserLastSubscriptionEventsById(User $user, $limit)
public function getUserLastSubscribersEventsById(User $user, $limit)
{
if (!is_int($limit)) {
throw new \InvalidArgumentException('$limit must be an integer');
@ -38,7 +38,8 @@ class SubscriptionEventRepository extends EntityRepository
$qb = $this->createQueryBuilder('se');
return $qb
->select()
->select(['se', 's'])
->join('se.subscriber', 's')
->where('se.author = :author')
->orderBy('se.date', 'desc')
->setMaxResults($limit)