From 89005902e44973f798cfa903742c0d8b99345ce0 Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Wed, 27 Aug 2003 05:49:52 +0000
Subject: [PATCH] - Tested and committed Kjartan's performance patches.  (Fixed
 the access check   in update.php though.)

---
 database/database.mysql    | 11 +++++++----
 database/database.pgsql    |  9 ++++++---
 includes/tablesort.inc     | 13 +++++++++----
 modules/forum.module       |  4 ++--
 modules/forum/forum.module |  4 ++--
 update.php                 | 24 ++++++++++++++++++------
 6 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/database/database.mysql b/database/database.mysql
index e64bf687ad5d..94b71155108d 100644
--- a/database/database.mysql
+++ b/database/database.mysql
@@ -25,7 +25,8 @@ CREATE TABLE accesslog (
   url varchar(255) default NULL,
   hostname varchar(128) default NULL,
   uid int(10) unsigned default '0',
-  timestamp int(11) unsigned NOT NULL default '0'
+  timestamp int(11) unsigned NOT NULL default '0',
+  KEY accesslog_timestamp (timestamp)
 ) TYPE=MyISAM;
 
 --
@@ -280,11 +281,13 @@ CREATE TABLE node (
   revisions text NOT NULL,
   static int(2) NOT NULL default '0',
   PRIMARY KEY  (nid),
-  KEY type (type),
-  KEY title (title,type),
-  KEY promote (promote),
+  KEY node_type (type(4)),
+  KEY node_title_type (title,type(4)),
   KEY status (status),
   KEY uid (uid)
+  KEY node_moderate (moderate);
+  KEY node_path (path(5));
+  KEY node_promote_status (promote, status);
 ) TYPE=MyISAM;
 
 --
diff --git a/database/database.pgsql b/database/database.pgsql
index 74b5cde3c088..d98bfcdcefdd 100644
--- a/database/database.pgsql
+++ b/database/database.pgsql
@@ -25,6 +25,7 @@ CREATE TABLE accesslog (
   uid integer default '0',
   timestamp integer NOT NULL default '0'
 );
+CREATE INDEX accesslog_timestamp_idx ON accesslog (timestamp);
 
 --
 -- Table structure for authmap
@@ -280,11 +281,13 @@ CREATE TABLE node (
   static integer NOT NULL default '0',
   PRIMARY KEY  (nid)
 );
-CREATE INDEX node_type_idx ON node(type);
-CREATE INDEX node_title_idx ON node(title,type);
-CREATE INDEX node_promote_idx ON node(promote);
+CREATE INDEX node_type_idx ON node(type(4));
+CREATE INDEX node_title_idx ON node(title,type(4));
 CREATE INDEX node_status_idx ON node(status);
 CREATE INDEX node_uid_idx ON node(uid);
+CREATE INDEX node_moderate_idx ON node (moderate);
+CREATE INDEX node_path_idx ON node (path(8));
+CREATE INDEX node_promote_status_idx ON node (promote, status);
 
 --
 -- Table structure for page
diff --git a/includes/tablesort.inc b/includes/tablesort.inc
index b0a17b027f82..65b0fdca24f1 100644
--- a/includes/tablesort.inc
+++ b/includes/tablesort.inc
@@ -14,7 +14,9 @@ function tablesort_init($header) {
 }
 
 function tablesort_pager() {
-  return array ("order" => $_GET['order'], "sort" => $_GET['sort']);
+  $cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST;
+  unset($cgi["q"], $cgi["from"]);
+  return $cgi;
 }
 
 function tablesort_sql($header) {
@@ -26,19 +28,22 @@ function tablesort($cell, $header) {
   global $theme;
 
   $ts = tablesort_init($header);
+  $title = t("sort by %s", array("%s" => $cell["data"]));
 
   // special formatting for the currently sorted column header
   if ($cell["data"] == $ts["order"]) {
     $cell["class"] = "cell-highlight";
-    $image = "&nbsp;<img src=\"". $theme->image("arrow-". $ts["sort"]. ".gif"). "\"></img>";
+    $image = "&nbsp;<img border=\"0\" src=\"". $theme->image("arrow-". $ts["sort"]. ".gif"). "\"></img>";
+    $dir = array("asc" => "ascending", "desc" => "descending");
+    $title = t("sort ". $dir[$ts["sort"]]);
   }
-  $cell["data"] = l($cell["data"] . $image, $_GET["q"], array(), "sort=". $ts["sort"]. "&order=". urlencode($cell["data"]). $ts["query_string"]);
+
+  $cell["data"] = l($cell["data"] . $image, $_GET["q"], array("title" => $title), "sort=". $ts["sort"]. "&order=". urlencode($cell["data"]). $ts["query_string"]);
   return $cell;
 }
 
 function tablesort_get_querystring() {
   $cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST;
-  // reset ($cgi);
   foreach ($cgi as $key => $val) {
     if ($key != "order" && $key != "sort" && $key != "q") {
       $query_string .= "&" . $key . "=" . $val;
diff --git a/modules/forum.module b/modules/forum.module
index 35f4b8e2b7c6..6378e3e34274 100644
--- a/modules/forum.module
+++ b/modules/forum.module
@@ -82,9 +82,9 @@ function forum_block($op = "list", $delta = 0) {
   }
   else {
     if (user_access("access content")) {
-      $content = node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'forum' AND n.nid = f.nid AND n.status = 1 GROUP BY n.nid, n.title, n.created, u.uid, u.name ORDER BY sort DESC", 0, variable_get("forum_block_num", "5")), t("Active forum topics:"));
+      $content = node_title_list(db_query_range("SELECT n.nid, n.title, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.type = 'forum' AND n.status = 1 GROUP BY n.nid, n.title, n.created ORDER BY sort DESC", 0, variable_get("forum_block_num", "5")), t("Active forum topics:"));
 
-      $content .= node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'forum' ORDER BY n.nid DESC", 0, variable_get("forum_block_num", "5")), t("New forum topics:"));
+      $content .= node_title_list(db_query_range("SELECT nid, title FROM {node} WHERE type = 'forum' ORDER BY nid DESC", 0, variable_get("forum_block_num", "5")), t("New forum topics:"));
 
       if ($content) {
         $content .= "<div class=\"more-link\">". l(t("more"), "forum", array("title" => t("Read the latest forum topics."))) ."</div>";
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 35f4b8e2b7c6..6378e3e34274 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -82,9 +82,9 @@ function forum_block($op = "list", $delta = 0) {
   }
   else {
     if (user_access("access content")) {
-      $content = node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'forum' AND n.nid = f.nid AND n.status = 1 GROUP BY n.nid, n.title, n.created, u.uid, u.name ORDER BY sort DESC", 0, variable_get("forum_block_num", "5")), t("Active forum topics:"));
+      $content = node_title_list(db_query_range("SELECT n.nid, n.title, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.type = 'forum' AND n.status = 1 GROUP BY n.nid, n.title, n.created ORDER BY sort DESC", 0, variable_get("forum_block_num", "5")), t("Active forum topics:"));
 
-      $content .= node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'forum' ORDER BY n.nid DESC", 0, variable_get("forum_block_num", "5")), t("New forum topics:"));
+      $content .= node_title_list(db_query_range("SELECT nid, title FROM {node} WHERE type = 'forum' ORDER BY nid DESC", 0, variable_get("forum_block_num", "5")), t("New forum topics:"));
 
       if ($content) {
         $content .= "<div class=\"more-link\">". l(t("more"), "forum", array("title" => t("Read the latest forum topics."))) ."</div>";
diff --git a/update.php b/update.php
index 1b7a72325224..2ef151b6b8f2 100644
--- a/update.php
+++ b/update.php
@@ -42,7 +42,8 @@
   "2003-06-08: first update since Drupal 4.2.0 release" => "update_58",
   "2003-08-05" => "update_59",
   "2003-08-15" => "update_60",
-  "2003-08-20" => "update_61"
+  "2003-08-20" => "update_61",
+  "2003-08-27" => "update_62"
 );
 
 function update_32() {
@@ -349,6 +350,21 @@ function update_61() {
   update_sql("ALTER TABLE {users} DROP sid;");
 }
 
+function update_62() {
+  update_sql("ALTER TABLE accesslog ADD INDEX accesslog_timestamp (timestamp)");
+
+  update_sql("ALTER TABLE node DROP INDEX type");
+  update_sql("ALTER TABLE node DROP INDEX title");
+  update_sql("ALTER TABLE node DROP INDEX promote");
+  update_sql("ALTER TABLE node DROP INDEX type");
+
+  update_sql("ALTER TABLE node ADD INDEX node_type (type(4))");
+  update_sql("ALTER TABLE node ADD INDEX node_title_type (title,type(4))");
+  update_sql("ALTER TABLE node ADD INDEX node_moderate (moderate)");
+  update_sql("ALTER TABLE node ADD INDEX node_path (path(5))");
+  update_sql("ALTER TABLE node ADD INDEX node_promote_status (promote, status)");
+}
+
 function _update_next_thread($structure, $parent) {
   do {
     $val++;
@@ -378,9 +394,6 @@ function update_sql($sql) {
   }
   else {
     print "<div style=\"color: red;\">FAILED</div>\n";
-    if ($edit["bail"]) {
-      die("Fatal error. Bailing");
-    }
     return 0;
   }
 }
@@ -450,7 +463,6 @@ function update_page() {
 
       // make update form and output it.
       $form .= form_select("Perform updates from", "start", (isset($selected) ? $selected : -1), $dates, "This defaults to the first available update since the last update you peformed.");
-      $form .= form_select("Stop on errors", "bail", 0, array("Disabled", "Enabled"), "Don't forget to backup your database before performing an update.");
       $form .= form_submit("Update");
       print update_page_header("Drupal database update");
       print form($form);
@@ -465,7 +477,7 @@ function update_info() {
   print "<li>Use this script to <b>upgrade an existing Drupal installation</b>.  You don't need this script when installing Drupal from scratch.</li>";
   print "<li>Before doing anything, backup your database. This process will change your database and its values, and some things might get lost.</li>\n";
   print "<li>Don't run this script twice as it may cause problems.</p></li>\n";
-  print "<li><a href=\"update.php?op=update\">Upgrade to CVS</a></li>\n";
+  print "<li><a href=\"update.php?op=update\">Upgrade to the latest version.</a></li>\n";
   print "<li>Go through the various administration pages to change the existing and new settings to your liking.</li>\n";
   print "</ol>";
   print update_page_footer();
-- 
GitLab