Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Articles performance fix

I've just fixed a performance R0;bugR1; on articles category list. A user on the Polish support reported that his vanilla PHP-Fusion is killing 4th server (VPS) with 2k unique entries per day. He uses Fusion for articles (4 752 records, 58,6 MB :D) in 45 categories. The problem: counting articles (article.php row 19) takes a lot of time [2.5 s. on my localhost, which is very slow].
Solution: PREFIX_article_cats gets article_cat_count field for the number of articles :)

- in phpMyAdmin execute:
ALTER TABLE `PREFIX_article_cats` ADD `article_cat_count` INT UNSIGNED NOT NULL DEFAULT '0';
UPDATE PREFIX_article_cats SET article_cat_count=(SELECT COUNT(*) FROM PREFIX_articles WHERE article_cat=article_cat_id)

open administration/article.php, row 52:
         $result = dbquery("INSERT INTO ".$db_prefix."articles (article_cat, article_subject, article_snippet, article_article, article_breaks, article_name, article_datestamp, article_reads, article_allow_comments, article_allow_ratings) VALUES ('".$_POST['article_cat']."', '$subject', '$body', '$body2', '$breaks', '".$userdata['user_id']."', '".time()."', '0', '$comments', '$ratings')");

$result = dbquery("UPDATE ".$db_prefix."article_cats SET article_cat_count=article_cat_count+1 WHERE article_cat_id='".$_POST['article_cat']."'");

open article.php row 17- 36:
if (!isset($cat_id)) {
} else {

if (!isset($cat_id)) {
   $result = dbquery("SELECT article_cat_id, article_cat_name, article_cat_description, article_cat_count FROM ".$db_prefix."article_cats WHERE ".groupaccess('article_cat_access')." ORDER BY article_cat_name");
   $rows = 1;
   if ($rows != 0) {
      $counter = 0; $columns = 2;
      echo "<table cellpadding='0' cellspacing='0' width='100%' class='tbl'>\n<tr>\n";
      while ($data = dbarray($result)) {
         if ($counter != 0 && ($counter % $columns == 0)) echo "</tr>\n<tr>\n";
         echo "<td align='center' valign='top' width='50%'><a href='".FUSION_SELF."?cat_id=".$data['article_cat_id']."'>".$data['article_cat_name']."</a> <span class='small2'>(".$data['article_cat_count'].")</span>";
         if ($data['article_cat_description'] != "") echo "<br>\n<span class='small'>".$data['article_cat_description']."</span>";
         echo "</td>\n";
      echo "</tr>\n</table>\n";
   } else {
      echo "<center><br>\n".$locale['401']."<br><br>\n</center>\n";
} else {

result: xdebug says that /articles.php category view executes now in ~0.0260 s :) not 3 s.
Thread Information
1 post
3095 times
Last Post
Last updated on 13 years ago
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.