Skip to content
Browse files

fixed comment counter on posts

  • Loading branch information...
1 parent ec4913c commit 955637c59a52a28723be94887bf52d86350e65ce @ubrog committed Apr 15, 2012
Showing with 3 additions and 5 deletions.
  1. +3 −5 src/APV/ForumBundle/Controller/DefaultController.php
View
8 src/APV/ForumBundle/Controller/DefaultController.php
@@ -50,12 +50,11 @@ public function listAction() {
$posts = $query->getResult();
// comments counter
- // TODO: optimize for faster counting
$commentsCount = array();
foreach ($posts as $post) {
$id = 'forum-post-' . $post->getId();
$thread = $this->container->get('fos_comment.manager.thread')->findThreadById($id);
-
+
if (null === $thread) {
$thread = $this->container->get('fos_comment.manager.thread')->createThread();
$thread->setId($id);
@@ -64,10 +63,9 @@ public function listAction() {
// Add the thread
$this->container->get('fos_comment.manager.thread')->saveThread($thread);
}
-
- $comments = $this->container->get('fos_comment.manager.comment')->findCommentTreeByThread($thread);
- $commentsCount[$post->getId()] = count($comments);
+ $commentsCount[$post->getId()] = $thread->getNumComments();
+
}
return $this->render('APVForumBundle:Default:list.html.twig', array('posts' => $posts, 'commentsCount' => $commentsCount));

0 comments on commit 955637c

Please sign in to comment.
Something went wrong with that request. Please try again.