Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.673
diff -u -p -r1.673 comment.module
--- modules/comment/comment.module	20 Dec 2008 18:24:35 -0000	1.673
+++ modules/comment/comment.module	25 Dec 2008 06:29:18 -0000
@@ -696,6 +696,18 @@ function comment_user_delete(&$edit, &$u
 }
 
 /**
+ * Implementation of hook_comment().
+ */
+function comment_comment($comment, $op) {
+  switch ($op) {
+    case 'insert':
+    case 'update':
+      $_SESSION['ignore_slave_server'] = REQUEST_TIME + variable_get('maximal_replication_lag', 10);
+      break;
+  }
+}
+
+/**
  * This is *not* a hook_access() implementation. This function is called
  * to determine whether the current user has access to a particular comment.
  *
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.1004
diff -u -p -r1.1004 node.module
--- modules/node/node.module	20 Dec 2008 18:24:38 -0000	1.1004
+++ modules/node/node.module	25 Dec 2008 06:29:20 -0000
@@ -1492,6 +1492,21 @@ function node_user_delete(&$edit, &$user
 }
 
 /**
+ * Implementation of hook_nodeapi_insert().
+ */
+function node_nodeapi_insert(&$node) {
+  $_SESSION['ignore_slave_server'] = REQUEST_TIME + variable_get('maximal_replication_lag', 10);
+}
+
+/**
+ * Implementation of hook_nodeapi_update().
+ */
+function node_nodeapi_update(&$node) {
+  $_SESSION['ignore_slave_server'] = REQUEST_TIME + variable_get('maximal_replication_lag', 10);
+}
+
+
+/**
  * Theme the content ranking part of the search settings admin page.
  *
  * @ingroup themeable
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.653
diff -u -p -r1.653 system.module
--- modules/system/system.module	24 Dec 2008 09:59:22 -0000	1.653
+++ modules/system/system.module	25 Dec 2008 06:29:22 -0000
@@ -741,6 +741,24 @@ function system_init() {
   drupal_add_css(drupal_get_path('module', 'system') . '/defaults.css');
   drupal_add_css(drupal_get_path('module', 'system') . '/system.css');
   drupal_add_css(drupal_get_path('module', 'system') . '/system-menus.css');
+
+  // Ignore slave database servers for this request.
+  // There are times when we will want to avoid using a slave server temporarily.
+  // For example, if a user posts a new node then we want to disable the slave
+  // server for that user temporarily to allow the slave server to catch up.
+  // That way, that user will see their changes immediately while for other
+  // users we still get the benefits of having a slave server, just with slightly
+  // stale data.  Code that wants to disable the slave server should set
+  // $_SESSION['ignore_slave_server'] to the timestamp after which the slave
+  // can be re-enabled.
+  if (isset($_SESSION['ignore_slave_server'])) {
+    if ($_SESSION['ignore_slave_server'] < REQUEST_TIME) {
+      Database::ignoreTarget('default', 'slave');
+    }
+    else {
+      unset($_SESSION['ignore_slave_server']);
+    }
+  }
 }
 
 /**
