Index: comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.692 diff -u -r1.692 comment.module --- modules/comment/comment.module 7 Feb 2009 20:10:40 -0000 1.692 +++ modules/comment/comment.module 8 Feb 2009 06:49:27 -0000 @@ -726,6 +726,18 @@ } /** + * Implementation of hook_comment(). + */ +function comment_comment($comment, $op) { + switch ($op) { + case 'insert': + case 'update': + drupal_set_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: node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1023 diff -u -r1.1023 node.module --- modules/node/node.module 6 Feb 2009 16:25:08 -0000 1.1023 +++ modules/node/node.module 8 Feb 2009 06:50:04 -0000 @@ -1595,6 +1595,21 @@ } /** + * Implementation of hook_nodeapi_insert(). + */ +function node_nodeapi_insert(&$node) { + drupal_set_session('ignore_slave_server',REQUEST_TIME + variable_get('maximal_replication_lag', 10)); +} + +/** + * Implementation of hook_nodeapi_update(). + */ +function node_nodeapi_update(&$node) { + drupal_set_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: system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.666 diff -u -r1.666 system.module --- modules/system/system.module 3 Feb 2009 18:55:31 -0000 1.666 +++ modules/system/system.module 8 Feb 2009 06:31:43 -0000 @@ -800,6 +800,24 @@ 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']); + } + } } /**