Index: privatemsg.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg.install,v
retrieving revision 1.20
diff -u -p -r1.20 privatemsg.install
--- privatemsg.install	20 Oct 2010 12:52:58 -0000	1.20
+++ privatemsg.install	15 Feb 2011 10:30:58 -0000
@@ -54,10 +54,9 @@ function privatemsg_schema() {
     ),
     'primary key'     => array('mid', 'recipient', 'type'),
     'indexes'         => array(
-      'mid'               => array('mid'),
-      'thread_id'         => array('thread_id'),
-      'recipient'         => array('recipient', 'type'),
-      'is_new'            => array('mid', 'recipient', 'type', 'is_new'),
+      'list'          => array('recipient', 'type', 'deleted', 'is_new'),
+      'messages'      => array('mid', 'recipient', 'type'),
+      'participants'  => array('thread_id', 'recipient', 'type', 'deleted'),
     ),
   );
 
@@ -103,11 +102,6 @@ function privatemsg_schema() {
       ),
     ),
     'primary key'     => array('mid'),
-    'indexes'         => array(
-      'author'            => array('author'),
-      'subject'           => array(array('subject', 20)),
-      'timestamp'         => array('timestamp'),
-    ),
   );
 
   $schema['pm_disable'] = array(
@@ -517,11 +511,6 @@ function privatemsg_update_6006() {
 function privatemsg_update_6200() {
   $ret = array();
 
-  // Make sure to not run this update twice.
-  if (db_table_exists('pm_disable')) {
-    return $ret;
-  }
-
   $schema['pm_disable'] = array(
     'description'       => '{pm_disable} holds the list of users that have disabled private messaging',
     'fields' => array(
@@ -552,8 +541,9 @@ function privatemsg_update_6201() {
   if (db_column_exists('pm_index', 'recipient')) {
     return $ret;
   }
-  db_drop_index($ret, 'pm_index', 'uid');
-  db_drop_index($ret, 'pm_index', 'is_new');
+  db_drop_index($ret, 'pm_index', 'list');
+  db_drop_index($ret, 'pm_index', 'messages');
+  db_drop_index($ret, 'pm_index', 'participants');
   db_change_field($ret, 'pm_index', 'uid', 'recipient', array(
     'description'   => 'ID of the recipient object, typically user',
     'type'          => 'int',
@@ -561,15 +551,18 @@ function privatemsg_update_6201() {
     'unsigned'      => TRUE,
   ));
   db_add_field($ret, 'pm_index', 'type', array(
-        'description'   => 'Type of recipient object',
-        'type' => 'varchar',
-        'not null' => TRUE,
-        'length'  => '255',
-        'default' => 'user'
-      ), array('indexes' => array(
-      'recipient'         => array('recipient', 'type'),
-      'is_new'            => array('mid', 'recipient', 'type', 'is_new')
-  )));
+      'description'   => 'Type of recipient object',
+      'type' => 'varchar',
+      'not null' => TRUE,
+      'length'  => '255',
+      'default' => 'user'
+    ), array(
+    'indexes' => array(
+      'list'         => array('recipient', 'type', 'deleted', 'is_new'),
+      'messages'     => array('mid', 'recipient', 'type'),
+      'participants' => array('thread_id', 'recipient', 'type', 'deleted'),
+    ),
+  ));
   return $ret;
 }
 
@@ -630,10 +623,64 @@ function privatemsg_update_6202(&$sandbo
  */
 function privatemsg_update_6203() {
   $ret = array();
-  db_add_primary_key($ret, 'pm_index', array('mid', 'recipient', 'type'));
-  // Ignore error that happens when this update runs twice.
-  if (!$ret[0]['success']) {
-    unset($ret[0]);
+  if (!privatemsg_db_index_exists('pm_index', 'PRIMARY')) {
+    db_add_primary_key($ret, 'pm_index', array('mid', 'recipient', 'type'));
+  }
+  return $ret;
+}
+
+/**
+ * Update indexes for 6.x-2.x instances.
+ */
+function privatemsg_update_6204() {
+  $ret = array();
+
+  // Remove whatever old indexes are on the tables.
+  $old = array(
+    'pm_index' => array('mid', 'thread_id', 'recipient', 'is_new'),
+    'pm_message' => array('author', 'subject', 'timestamp'),
+  );
+  foreach ($old as $table => $indexes) {
+    foreach ($indexes as $name) {
+      if (privatemsg_db_index_exists($table, $name)) {
+        db_drop_index($ret, $table, $name);
+      }
+    }
+  }
+
+  $new = array(
+    'list'         => array('recipient', 'type', 'deleted', 'is_new'),
+    'messages'     => array('mid', 'recipient', 'type'),
+    'participants' => array('thread_id', 'recipient', 'type', 'deleted'),
+  );
+  foreach ($new as $name => $fields) {
+    if (!privatemsg_db_index_exists('pm_index', $name)) {
+      db_add_index($ret, 'pm_index', $name, $fields);
+    }
   }
+
   return $ret;
 }
+
+/**
+ * Checks if an index exists in the given table.
+ *
+ * @param $table
+ *   The name of the table in drupal (no prefixing).
+ * @param $name
+ *   The name of the index in drupal (no prefixing).
+ *
+ * @return
+ *   TRUE if the given index exists, otherwise FALSE.
+ */
+function privatemsg_db_index_exists($table, $name) {
+  global $db_type;
+
+  if ($db_type == 'pgsql') {
+    $index_name = '{' . $table . '}_' . $name . '_idx';
+    return (bool) db_result(db_query("SELECT 1 FROM pg_indexes WHERE indexname = '$index_name'"));
+  }
+  else {
+    return (bool)db_fetch_array(db_query('SHOW INDEX FROM {' . $table . "} WHERE key_name = '$name'"));
+  }
+}
Index: privatemsg_filter/privatemsg_filter.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg_filter/privatemsg_filter.install,v
retrieving revision 1.7
diff -u -p -r1.7 privatemsg_filter.install
--- privatemsg_filter/privatemsg_filter.install	20 Oct 2010 12:52:58 -0000	1.7
+++ privatemsg_filter/privatemsg_filter.install	15 Feb 2011 10:30:59 -0000
@@ -42,7 +42,10 @@ function privatemsg_filter_schema() {
         'default'       => 0,
       )
     ),
-    'primary key'     => array('tag_id')
+    'primary key'     => array('tag_id'),
+    'indexes'     => array(
+      'tag_list'    => array('tag_id', 'tag', 'public'),
+    ),
   );
 
   $schema['pm_tags_index'] = array(
@@ -69,7 +72,7 @@ function privatemsg_filter_schema() {
     ),
     'primary key'     => array('tag_id', 'uid', 'thread_id'),
     'indexes'         => array(
-     'uid'            => array('uid'),
+     'thread_tags'      => array('uid', 'thread_id'),
     ),
   );
 
@@ -194,3 +197,20 @@ function privatemsg_filter_update_6201(&
   $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['current_thread_id'] / $sandbox['max']);
   return $ret;
 }
+
+/**
+ * Add new indexes to existing 6.x-2.x installations.
+ */
+function privatemsg_filter_update_6202() {
+  $ret = array();
+  if (!privatemsg_db_index_exists('pm_tags', 'tag_list')) {
+    db_add_index($ret, 'pm_tags', 'tag_list', array('tag_id', 'tag', 'public'));
+  }
+  if (privatemsg_db_index_exists('pm_tags_index', 'uid')) {
+    db_drop_index($ret, 'pm_tags_index', 'uid');
+  }
+  if (!privatemsg_db_index_exists('pm_tags_index', 'thread_tags')) {
+    db_add_index($ret, 'pm_tags_index', 'thread_tags', array('uid', 'thread_id'));
+  }
+  return $ret;
+}
