Our Discourse forum has received a mixed approval rating. Many folks like it, but others still find it lacking in areas in certain clients. Well, no matter your opinion, I can guarantee that, as it was true when the article first ran, our forum doesn't have the same problem mentioned below.


"Having recently upgraded my forum software," Kinta wrote, "I noticed that my site had been running incredibly slow."

"Upon further investigation, I found that that the following code was being run once for each and every comment on a page, whenever ever a forum thread was opened.

 

function ItemCache($bNewConnection = false)
{
   $this->sql = new SqlHelper(dbhost, dbname, dbuser, dbpass, $bNewConnection);
   $this->connected = $this->sql->connected;

   $query = "SELECT item_id FROM item_cache";
   $returnValue = $this->sql->query($query);
     
   if ($returnValue == false)
   {
      $query = "ALTER TABLE item_cache ADD `item_id` 
                VARCHAR(100) DEFAULT '0' AFTER `item_name`";
      $returnValue = $this->sql->query($query);
         
      $query = "ALTER TABLE item_cache ADD `item_lang`
                VARCHAR(2) DEFAULT '' AFTER `item_id`";
      $returnValue2 = $this->sql->query($query);
         
      if ($returnValue == false || $returnValue2 == false)
      {
        // Create the item cache table.
        $query = "CREATE TABLE IF NOT EXISTS `item_cache` (
                  ### snip ###
        $this->sql->query($query);
      }
   }
}

"It's fetching data from all rows from the entire item_cache table (currently several thousand), twenty-five times for every page load... just to check if the table exists and has the right columns.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!