public function UpdateDiscussionCount($CategoryID, $Discussion = FALSE) {
      $DiscussionID = GetValue('DiscussionID', $Discussion, FALSE);
		if (strcasecmp($CategoryID, 'All') == 0) {
			$Exclude = (bool)Gdn::Config('Vanilla.Archive.Exclude');
			$ArchiveDate = Gdn::Config('Vanilla.Archive.Date');
			$Params = array();
			$Where = '';
			
			if($Exclude && $ArchiveDate) {
				$Where = 'where d.DateLastComment > :ArchiveDate';
				$Params[':ArchiveDate'] = $ArchiveDate;
			}
			
			// Update all categories.
			$Sql = "update :_Category c
            left join (
              select
                d.CategoryID,
                coalesce(count(d.DiscussionID), 0) as CountDiscussions,
                coalesce(sum(d.CountComments), 0) as CountComments
              from :_Discussion d
              $Where
              group by d.CategoryID
            ) d
              on c.CategoryID = d.CategoryID
            set 
               c.CountDiscussions = coalesce(d.CountDiscussions, 0),
               c.CountComments = coalesce(d.CountComments, 0)";
			$Sql = str_replace(':_', $this->Database->DatabasePrefix, $Sql);
			$this->Database->Query($Sql, $Params, 'DiscussionModel_UpdateDiscussionCount');
			
		} elseif (is_numeric($CategoryID)) {
         $this->SQL
            ->Select('d.DiscussionID', 'count', 'CountDiscussions')
            ->Select('d.CountComments', 'sum', 'CountComments')
            ->From('Discussion d')
            ->Where('d.CategoryID', $CategoryID);
         
			$this->AddArchiveWhere();
			
			$Data = $this->SQL->Get()->FirstRow();
         $CountDiscussions = (int)GetValue('CountDiscussions', $Data, 0);
         $CountComments = (int)GetValue('CountComments', $Data, 0);
         
         $CacheAmendment = array(
            'CountDiscussions'      => $CountDiscussions,
            'CountComments'         => $CountComments
         );
         
         if ($DiscussionID) {
            $CacheAmendment = array_merge($CacheAmendment, array(
               'LastDiscussionID'   => $DiscussionID,
               'LastCommentID'      => NULL,
               'LastDateInserted'   => GetValue('DateInserted', $Discussion)
            ));
         }
         
         $CategoryModel = new CategoryModel();
         $CategoryModel->SetField($CategoryID, $CacheAmendment);
         $CategoryModel->SetRecentPost($CategoryID);
      }
   }