Index: privatemsg.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/privatemsg/privatemsg.module,v
retrieving revision 1.70.2.30.2.91.2.53
diff -u -p -r1.70.2.30.2.91.2.53 privatemsg.module
--- privatemsg.module	8 Jun 2009 14:27:53 -0000	1.70.2.30.2.91.2.53
+++ privatemsg.module	8 Jun 2009 19:42:43 -0000
@@ -254,6 +254,7 @@ function privatemsg_view_access() {
  * @ingroup api
  */
 function privatemsg_thread_load($thread_id, $account = NULL) {
+  static $threads = array();
   if ((int)$thread_id > 0) {
     $thread = array('thread_id' => $thread_id);
 
@@ -261,31 +262,39 @@ function privatemsg_thread_load($thread_
       global $user;
       $account = drupal_clone($user);
     }
-    // load messages returned by the messages query with _privatemsg_load().
-    $query = _privatemsg_assemble_query('messages', array($thread_id), $account);
-    $conversation = db_query($query['query']);
-    while ($result = db_fetch_array($conversation)) {
-      if ($message = _privatemsg_load($result['mid'], $account)) {
-        $thread['messages'][$result['mid']] = $message;
-      }
+
+    if (!isset($threads[$account->uid])) {
+      $threads[$account->uid] = array();
     }
-    // if there are no messages, don't allow access to the thread.
-    if (empty($thread['messages'])) {
-      return FALSE;
-    }
-
-    // general data, assume subject is the same for all messages of that thread.
-    $thread['user'] = $account;
-    $message = current($thread['messages']);
-    $thread['subject'] = $message['subject'];
-
-    // Load the list of participants.
-    $query = _privatemsg_assemble_query('participants', $thread_id);
-    $participants = db_query($query['query']);
-    while ($result = db_fetch_array($participants)) {
-      $thread['participants'][$result['uid']] = user_load($result['uid']);
+
+    if (!array_key_exists($thread_id, $threads[$account->uid])) {
+      // load messages returned by the messages query with _privatemsg_load().
+      $query = _privatemsg_assemble_query('messages', array($thread_id), $account);
+      $conversation = db_query($query['query']);
+      while ($result = db_fetch_array($conversation)) {
+        if ($message = _privatemsg_load($result['mid'], $account)) {
+          $thread['messages'][$result['mid']] = $message;
+        }
+      }
+      // if there are no messages, don't allow access to the thread.
+      if (empty($thread['messages'])) {
+        $threads[$account->uid][$thread_id] = FALSE;
+      } else {
+        // general data, assume subject is the same for all messages of that thread.
+        $thread['user'] = $account;
+        $message = current($thread['messages']);
+        $thread['subject'] = $message['subject'];
+
+        // Load the list of participants.
+        $query = _privatemsg_assemble_query('participants', $thread_id);
+        $participants = db_query($query['query']);
+        while ($result = db_fetch_array($participants)) {
+          $thread['participants'][$result['uid']] = user_load($result['uid']);
+        }
+        $threads[$account->uid][$thread_id] = $thread;
+      }
     }
-    return $thread;
+    return $threads[$account->uid][$thread_id];
   }
   return FALSE;
 }
