Development

Changeset 5403

You must first sign up to be able to contribute.

Changeset 5403

Show
Ignore:
Timestamp:
10/07/07 13:12:25 (6 years ago)
Author:
francois
Message:

sfSimpleForumPlugin Further optimized queries

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfSimpleForumPlugin/trunk/CHANGELOG

    r5357 r5403  
    11== Trunk == 
    22 
     3 * francois: Further optimized queries 
     4  
    35== 2007-10-03 | 0.6.3 Beta == 
    46 
  • plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPost.php

    r5356 r5403  
    124124  } 
    125125   
     126  public function getCreationTimestamp() 
     127  { 
     128    return $this->getCreatedAt('U'); 
     129  } 
    126130} 
  • plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPostPeer.php

    r5356 r5403  
    1111{ 
    1212   
    13   public static function setIsNewForUser($topics, $user_id) 
    14   { 
    15     $topic_ids  = array(); 
    16     $topic_hash = array(); 
    17     foreach ($topics as $topic) 
    18     { 
    19       // A topic is new unless we can find a view from the user for it 
    20       $topic->setIsNew(true); 
    21       $id = $topic->getId(); 
    22       $topic_ids[] = $id; 
    23       $topic_hash[$id] = $topic; 
    24     } 
    25      
    26     $c = new Criteria(); 
    27     $c->clearSelectColumns(); 
    28     $c->addSelectColumn(sfSimpleForumTopicViewPeer::TOPIC_ID); 
    29     $c->add(sfSimpleForumTopicViewPeer::USER_ID, $user_id); 
    30     $c->add(sfSimpleForumTopicViewPeer::TOPIC_ID, $topic_ids, Criteria::IN); 
    31     $rs = sfSimpleForumTopicViewPeer::doSelectRS($c); 
    32      
    33     while($rs->next()) 
    34     { 
    35       $topic = $topic_hash[$rs->getInt(1)]; 
    36       $topic->setIsNew(false); 
    37     } 
    38      
    39     return $topic_hash; 
    40   } 
    41    
     13  public static function getOneJoinForum($id) 
     14  { 
     15    $c = new Criteria(); 
     16    $c->add(self::ID, $id); 
     17    $c->setLimit(1); 
     18     
     19    $objects = self::doSelectJoinsfSimpleForumForum($c); 
     20     
     21    if ($objects)  
     22    { 
     23      return $objects[0]; 
     24    } 
     25    return null; 
     26  } 
    4227  public static function getLatestCriteria() 
    4328  { 
     
    6550    $pager->setPage($page); 
    6651    $pager->setCriteria($c); 
    67     $pager->setPeerMethod('doSelectJoinAllExceptsfGuardUser'); 
     52    $pager->setPeerMethod('doSelectJoinsfSimpleForumForum'); 
    6853    $pager->init(); 
    6954     
     
    130115    $pager->setPage($page); 
    131116    $pager->setCriteria($c); 
    132     $pager->setPeerMethod('doSelectJoinTopicAndForum'); 
     117    $pager->setPeerMethod('doSelectJoinsfSimpleForumForum'); 
    133118    $pager->init(); 
    134119 
     
    162147    $pager->setPage($page); 
    163148    $pager->setCriteria($c); 
    164     $pager->setPeerMethod('doSelectJoinTopicAndForum'); 
     149    $pager->setPeerMethod('doSelectJoinsfSimpleForumForum'); 
    165150    $pager->init(); 
    166151 
  • plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopicPeer.php

    r5287 r5403  
    1010class sfSimpleForumTopicPeer extends BasesfSimpleForumTopicPeer 
    1111{ 
     12  public static function setIsNewForUser($topics, $user_id) 
     13  { 
     14    $topic_ids  = array(); 
     15    $topic_hash = array(); 
     16    foreach ($topics as $topic) 
     17    { 
     18      // A topic is new unless we can find a view from the user for it 
     19      $topic->setIsNew(true); 
     20      $id = $topic->getId(); 
     21      $topic_ids[] = $id; 
     22      $topic_hash[$id] = $topic; 
     23    } 
     24     
     25    $c = new Criteria(); 
     26    $c->clearSelectColumns(); 
     27    $c->addSelectColumn(sfSimpleForumTopicViewPeer::TOPIC_ID); 
     28    $c->add(sfSimpleForumTopicViewPeer::USER_ID, $user_id); 
     29    $c->add(sfSimpleForumTopicViewPeer::TOPIC_ID, $topic_ids, Criteria::IN); 
     30    $rs = sfSimpleForumTopicViewPeer::doSelectRS($c); 
     31     
     32    while($rs->next()) 
     33    { 
     34      $topic = $topic_hash[$rs->getInt(1)]; 
     35      $topic->setIsNew(false); 
     36    } 
     37     
     38    return $topic_hash; 
     39  } 
     40   
    1241  public static function getLatestCriteria() 
    1342  { 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/lib/BasesfSimpleForumActions.class.php

    r5356 r5403  
    6060      sfConfig::get('app_sfSimpleForumPlugin_feed_max', 10) 
    6161    ); 
    62     $this->rule = 'sfSimpleForum/latestPosts'; 
     62    $this->rule = $this->getModuleName().'/latestPosts'; 
    6363    $this->feed_title = $this->getFeedTitle(); 
    6464     
     
    9090      sfConfig::get('app_sfSimpleForumPlugin_feed_max', 10) 
    9191    ); 
    92     $this->rule = 'sfSimpleForum/latestTopics'; 
     92    $this->rule = $this->getModuleName().'/latestTopics'; 
    9393    $this->feed_title = $this->getLatestTopicsFeedTitle(); 
    9494     
     
    119119    { 
    120120      // FIXME: When Propel can do a right join with multiple on conditions, merge this query with the pager's one 
    121       $this->topics = sfSimpleForumPostPeer::setIsNewForUser($this->topics, $this->getUser()->getGuardUser()->getId()); 
     121      $this->topics = sfSimpleForumTopicPeer::setIsNewForUser($this->topics, $this->getUser()->getGuardUser()->getId()); 
    122122    } 
    123123  } 
     
    141141      sfConfig::get('app_sfSimpleForumPlugin_feed_max', 10) 
    142142    ); 
    143     $this->rule = 'sfSimpleForum/forumLatestPosts?forum_name='.$this->name; 
     143    $this->rule = $this->getModuleName().'/forumLatestPosts?forum_name='.$this->name; 
    144144     
    145145    return $this->renderText($this->getFeedFromObjects($this->posts)); 
     
    196196    $this->forward404Unless($this->posts); 
    197197     
    198     $this->rule = 'sfSimpleForum/topic?id='.$this->getRequestParameter('id').'&stripped_title='.$this->getRequestParameter('forum_name'); 
     198    $this->rule = $this->getModuleName().'/topic?id='.$this->getRequestParameter('id').'&stripped_title='.$this->getRequestParameter('forum_name'); 
    199199     
    200200    return $this->renderText($this->getFeedFromObjects($this->posts)); 
     
    222222    $position = $post->getPositionInTopic(); 
    223223    $page = ceil(($position + 1) / sfConfig::get('app_sfSimpleForumPlugin_max_per_page', 10)); 
    224       $this->redirect('sfSimpleForum/topic?id='.$topic->getId().'&stripped_title='.$topic->getStrippedTitle().'&page='.$page.'#post'.$post->getId()); 
     224      $this->redirect($this->getModuleName().'/topic?id='.$topic->getId().'&stripped_title='.$topic->getStrippedTitle().'&page='.$page.'#post'.$post->getId()); 
    225225  } 
    226226   
     
    248248    ); 
    249249     
    250     $this->rule = 'sfSimpleForum/userLatestPosts?username='.$this->username; 
     250    $this->rule = $this->getModuleName().'/userLatestPosts?username='.$this->username; 
    251251    $this->feed_title = $this->getUserLatestPostsFeedTitle(); 
    252252     
     
    284284      sfConfig::get('app_sfSimpleForumPlugin_feed_max', 10) 
    285285    ); 
    286     $this->rule = 'sfSimpleForum/latestUserTopics?username='.$this->username; 
     286    $this->rule = $this->getModuleName().'/latestUserTopics?username='.$this->username; 
    287287    $this->feed_title = $this->getUserLatestTopicsFeedTitle(); 
    288288     
     
    403403    $position = $post->getPositionInTopic(); 
    404404    $page = ceil(($position + 1) / sfConfig::get('app_sfSimpleForumPlugin_max_per_page', 10)); 
    405     $this->redirect('sfSimpleForum/topic?id='.$post->getTopic()->getId().'&stripped_title='.$post->getTopic()->getStrippedTitle().'&page='.$page.'#post'.$post->getId());     
     405    $this->redirect($this->getModuleName().'/topic?id='.$post->getTopic()->getId().'&stripped_title='.$post->getTopic()->getStrippedTitle().'&page='.$page.'#post'.$post->getId());     
    406406  } 
    407407   
     
    417417      $topic->delete(); 
    418418      $forum = $post->getsfSimpleForumForum(); 
    419       $this->redirect('sfSimpleForum/forum?forum_name='.$forum->getStrippedName()); 
     419      $this->redirect($this->getModuleName().'/forum?forum_name='.$forum->getStrippedName()); 
    420420    } 
    421421    else 
     
    423423      // delete only one message and redirect to the topic 
    424424      $post->delete(); 
    425       $this->redirect('sfSimpleForum/topic?id='.$topic->getId().'&stripped_title='.$topic->getStrippedTitle()); 
     425      $this->redirect($this->getModuleName().'/topic?id='.$topic->getId().'&stripped_title='.$topic->getStrippedTitle()); 
    426426    } 
    427427  } 
     
    435435     
    436436    $forum = $topic->getsfSimpleForumForum(); 
    437     $this->redirect('sfSimpleForum/forum?forum_name='.$forum->getStrippedName()); 
     437    $this->redirect($this->getModuleName().'/forum?forum_name='.$forum->getStrippedName()); 
    438438  } 
    439439   
     
    449449    $topic->save(); 
    450450     
    451     $this->redirect('sfSimpleForum/topic?id='.$topic->getId()); 
     451    $this->redirect($this->getModuleName().'/topic?id='.$topic->getId()); 
    452452  } 
    453453   
     
    463463    $topic->save(); 
    464464     
    465     $this->redirect('sfSimpleForum/topic?id='.$topic->getId()); 
     465    $this->redirect($this->getModuleName().'/topic?id='.$topic->getId()); 
    466466  } 
    467467} 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_post.php

    r5312 r5403  
    1313      <?php echo link_to($post->getsfSimpleForumForum()->getName(), 'sfSimpleForum/forum?forum_name='.$post->getsfSimpleForumForum()->getStrippedName()) ?> 
    1414     &raquo; 
    15       <?php echo link_to($post->getsfSimpleForumTopic()->getTitle(), 'sfSimpleForum/post?id='.$post->getId()) ?> 
     15      <?php echo link_to($post->getTitle(), 'sfSimpleForum/post?id='.$post->getId()) ?> 
    1616      <?php endif ?> 
    1717    </div>