cvs diff: Diffing .
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	20 Apr 2009 20:40:27 -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:'. $pid;
+      _project_issue_block_cache_set($cid);
+    }
+  }
 }
 
 /**
@@ -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	20 Apr 2009 20:40:28 -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.
+  _project_issue_block_cache_set('project_issue_cockpit:'. $node->pid);
 }
 
 function project_issue_delete($node) {
Index: project_issue.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.install,v
retrieving revision 1.60
diff -u -p -r1.60 project_issue.install
--- project_issue.install	20 Apr 2009 19:24:42 -0000	1.60
+++ project_issue.install	20 Apr 2009 20:40:28 -0000
@@ -313,6 +313,26 @@ function project_issue_schema() {
     'primary key' => array('sid'),
   );
 
+  $schema['project_issue_cache_block'] = array(
+    'description' => t('Cache for project_issue-specific blocks that cannot rely on the normal block cache.'),
+    'fields' => array(
+      'cid' => array(
+        'description' => 'Primary Key: Unique cache ID.',
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'data' => array(
+        'description' => 'A collection of data to cache.',
+        'type' => 'blob',
+        'not null' => FALSE,
+        'size' => 'big',
+      ),
+    ),
+    'primary key' => array('cid'),
+  );
+
   return $schema;
 }
 
@@ -416,3 +436,28 @@ function project_issue_update_6000() {
   return array();
 }
 
+/**
+ * Add the {project_issue_cache_block} table for the "issue cockpit" block.
+ */
+function project_issue_update_6001() {
+  $ret = array();
+  $table = array(
+    'fields' => array(
+      'cid' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'data' => array(
+        'type' => 'blob',
+        'not null' => FALSE,
+        'size' => 'big',
+      ),
+    ),
+    'primary key' => array('cid'),
+  );
+  db_create_table($ret, 'project_issue_cache_block', $table);
+  return $ret;
+}
+
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	20 Apr 2009 20:40:29 -0000
@@ -1640,13 +1640,42 @@ 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.
+    db_query("DELETE FROM {project_issue_cache_block} WHERE cid RLIKE 'project_issue_cockpit:'");
   }
   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:'. $node->nid;
+    $block = _project_issue_block_cache_get($cid);
+    if (empty($block)) {
+      module_load_include('inc', 'project_issue', 'includes/issue_cockpit');
+      $block = array(
+        'subject' => t('Issues'),
+        'content' => theme('project_issue_issue_cockpit', $node),
+      );
+      _project_issue_block_cache_set($cid, $block);
+      dvm("regenerated issue block");
+    }
+    return $block;
+  }
+}
+
+function _project_issue_block_cache_get($cid) {
+  $data = db_result(db_query("SELECT data FROM {project_issue_cache_block} WHERE cid = '%s'", $cid));
+  if (!empty($data)) {
+    return unserialize($data);
+  }
+}
+
+function _project_issue_block_cache_set($cid, $data = array()) {
+  if (empty($data)) {
+    db_query("DELETE FROM {project_issue_cache_block} WHERE cid = '%s'", $cid);
+  }
+  else {
+    $serialized = serialize($data);
+    db_query("UPDATE {project_issue_cache_block} SET data = '%s' WHERE cid = '%s'", $serialized, $cid);
+    if (!db_affected_rows()) {  
+      db_query("INSERT INTO {project_issue_cache_block} (cid, data) VALUES ('%s', '%s')", $cid, $serialized);
+    }
   }
 }
 
