Index: comment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/comment.inc,v
retrieving revision 1.152
diff -u -p -r1.152 comment.inc
--- comment.inc	20 Feb 2009 07:14:15 -0000	1.152
+++ comment.inc	4 May 2009 21:42:28 -0000
@@ -19,6 +19,11 @@ function project_issue_comment(&$arg, $o
   $old_data = (object) $original_node->project_issue;
   $old_data->title = $original_node->title;
 
+  // Maintain an array of project ids that are affected by this comment
+  // operation. We'll use this to invalidate the "Issue cockpit" block cache
+  // for any of these projects.
+  $affected_projects = array();
+
   switch ($op) {
     case 'insert':
       // Get a lock on the issue in order to generate the next comment ID.
@@ -44,6 +49,8 @@ function project_issue_comment(&$arg, $o
         db_query("INSERT INTO {project_issue_comments} (nid, cid, pid, rid, component, category, priority, assigned, sid, title, timestamp, comment_number) VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d, %d, '%s', %d, %d)", $arg['nid'], $arg['cid'], $arg['project_info']['pid'], $rid, $arg['project_info']['component'], $arg['category'], $arg['priority'], $arg['project_info']['assigned'], $arg['sid'], $arg['title'], $arg['timestamp'], $id);
         db_query("UPDATE {comments} SET subject = '%s' WHERE cid = %d", "#$id", $arg['cid']);
         project_issue_update_by_comment($arg, 'insert');
+        $affected_projects[$old_data->pid] = 1;
+        $affected_projects[$arg['project_info']['pid']] = 1;
       }
       else {
         drupal_set_message(t('There was an error submitting your comment -- please try again. If the problem persists, contact the system administrator.'), 'error');
@@ -60,11 +67,23 @@ function project_issue_comment(&$arg, $o
 
     case 'update':
       project_issue_update_by_comment($arg, 'update');
+      // Updating a comment can't change anything relevant about the issue for
+      // the purposes of the issue blocks, so we don't need to touch
+      // $affected_projects here.
       break;
 
     case 'delete':
+      // Save the project that's specified in this comment so we can
+      // invalidate its issue block cache.
+      $deleted_comment_project_id = db_result(db_query("SELECT pid FROM {project_issue_comments} WHERE cid = %d", $arg->cid));
+      $affected_projects[$deleted_comment_project_id] = 1;
+      // Actually delete the comment
       db_query("DELETE FROM {project_issue_comments} WHERE cid = %d", $arg->cid);
-      project_issue_update_by_comment($arg, 'delete');
+      $current_data = project_issue_update_by_comment($arg, 'delete');
+      // We should also invalidate the block cache for whatever project is now
+      // used for this issue, since we might be deleting a comment that moved
+      // an issue from one project to another.
+      $affected_projects[$current_data->pid] = 1;      
       break;
 
     case 'view':
@@ -88,6 +107,13 @@ function project_issue_comment(&$arg, $o
       break;
 
   }
+  // If there are any affected projects, invalidate the block cache for those.
+  if (!empty($affected_projects)) {
+    foreach ($affected_projects as $pid => $value) {
+      $cid = 'project_issue_cockpit_block:'. $pid;
+      cache_clear_all($cid, 'cache');
+    }
+  }
 }
 
 /**
@@ -508,6 +534,8 @@ function project_issue_comment_view(&$no
  *  The comment data that's been submitted.
  * @param $op
  *  The comment operation performed, 'insert', 'update', 'delete'.
+ * @return
+ *   An object representing the comment data used to update the issue.
  */
 function project_issue_update_by_comment($comment_data, $op) {
   switch ($op) {
@@ -542,6 +570,9 @@ function project_issue_update_by_comment
 
   // This also updates the changed date of the issue.
   node_save($node);
+
+  // Return the object of comment data we used to update the issue.
+  return $comment_data;
 }
 
 /**
Index: issue.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/issue.inc,v
retrieving revision 1.345
diff -u -p -r1.345 issue.inc
--- issue.inc	4 Apr 2009 07:03:28 -0000	1.345
+++ issue.inc	4 May 2009 21:42:29 -0000
@@ -1025,6 +1025,10 @@ function project_issue_insert($node) {
   }
 
   db_query("INSERT INTO {project_issues} (nid, pid, category, component, priority, rid, assigned, sid, original_issue_data, last_comment_id, db_lock) VALUES (%d, %d, '%s', '%s', %d, %d, %d, %d, '%s', %d, %d)", $node->nid, $node->pid, $node->category, $node->component, $node->priority, $node->rid, $node->assigned, $node->sid, serialize($original_issue_data), 0, 0);
+
+  // Invalidate the "Issue cockpit" block cache for this project, since the
+  // new issue will have altered the summary totals.
+  cache_clear_all('project_issue_cockpit_block:'. $node->pid, 'cache');
 }
 
 function project_issue_delete($node) {
Index: project_issue.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.module,v
retrieving revision 1.162
diff -u -p -r1.162 project_issue.module
--- project_issue.module	20 Apr 2009 19:11:34 -0000	1.162
+++ project_issue.module	4 May 2009 21:42:30 -0000
@@ -1640,13 +1640,23 @@ function project_issue_block($op = 'list
   }
   elseif ($op == 'save' && $delta == 'issue_cockpit') {
     variable_set('project_issue_cockpit_categories', $edit['project_issue_cockpit_categories']);
+    // Invalidate the cache for this block since the categories might change.
+    cache_clear_all('project_issue_cockpit_block:', 'cache', TRUE);
   }
   elseif ($op == 'view' && ($node = project_get_project_from_menu()) && !empty($node->project_issue['issues']) && node_access('view', $node)) {
-    module_load_include('inc', 'project_issue', 'includes/issue_cockpit');
-    return array(
-      'subject' => t('Issues'),
-      'content' => theme('project_issue_issue_cockpit', $node),
-    );
+    $cid = 'project_issue_cockpit_block:'. $node->nid;
+    if (($cache = cache_get($cid))) {
+      $block = $cache->data;
+    }
+    else {
+      module_load_include('inc', 'project_issue', 'includes/issue_cockpit');
+      $block = array(
+        'subject' => t('Issues'),
+        'content' => theme('project_issue_issue_cockpit', $node),
+      );
+      cache_set($cid, $block);
+    }
+    return $block;
   }
 }
 
