Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a parameter to node load for slavesafe, defaults to true and us…

…es db slave query, if set to false forces master query
  • Loading branch information...
commit 379b206125e26a3305678bd31396e9a368bf9359 1 parent 88ac16e
David Diers authored

Showing 1 changed file with 26 additions and 7 deletions. Show diff stats Hide diff stats

  1. +26 7 modules/node/node.module
33 modules/node/node.module
@@ -695,11 +695,13 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
695 695 * Which numbered revision to load. Defaults to the current version.
696 696 * @param $reset
697 697 * Whether to reset the internal node_load cache.
  698 + * @param $slavesafe
  699 + * Whether to use the slave db for node_load. Defaults to using slave db.
698 700 *
699 701 * @return
700 702 * A fully-populated node object.
701 703 */
702   -function node_load($param = array(), $revision = NULL, $reset = NULL) {
  704 +function node_load($param = array(), $revision = NULL, $reset = NULL, $slavesafe = TRUE) {
703 705 static $nodes = array();
704 706
705 707 if ($reset) {
@@ -744,14 +746,30 @@ function node_load($param = array(), $revision = NULL, $reset = NULL) {
744 746 // Change name of revision uid so it doesn't conflict with n.uid.
745 747 $fields = str_replace('r.uid', 'r.uid AS revision_uid', $fields);
746 748
747   - // Retrieve the node.
748   - // No db_rewrite_sql is applied so as to get complete indexing for search.
749   - if ($revision) {
750   - array_unshift($arguments, $revision);
751   - $node = db_fetch_object(db_query_slave('SELECT '. $fields .' FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond, $arguments));
  749 + // By default use slave db for node_loads.
  750 + if ($slavesafe) {
  751 + // Retrieve the node.
  752 + // No db_rewrite_sql is applied so as to get complete indexing for search.
  753 + if ($revision) {
  754 + array_unshift($arguments, $revision);
  755 + $node = db_fetch_object(db_query_slave('SELECT '. $fields .' FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond, $arguments));
  756 + }
  757 + else {
  758 + $node = db_fetch_object(db_query_slave('SELECT '. $fields .' FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond, $arguments));
  759 + }
752 760 }
  761 + // Force node loads from the master. Not the most efficient, but in use.
  762 + // See http://buytaert.net/database-replication-lag.
753 763 else {
754   - $node = db_fetch_object(db_query_slave('SELECT '. $fields .' FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond, $arguments));
  764 + // Retrieve the node.
  765 + // No db_rewrite_sql is applied so as to get complete indexing for search.
  766 + if ($revision) {
  767 + array_unshift($arguments, $revision);
  768 + $node = db_fetch_object(db_query('SELECT '. $fields .' FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond, $arguments));
  769 + }
  770 + else {
  771 + $node = db_fetch_object(db_query('SELECT '. $fields .' FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond, $arguments));
  772 + }
755 773 }
756 774
757 775 if ($node && $node->nid) {
@@ -776,6 +794,7 @@ function node_load($param = array(), $revision = NULL, $reset = NULL) {
776 794 return $node;
777 795 }
778 796
  797 +
779 798 /**
780 799 * Perform validation checks on the given node.
781 800 */

0 comments on commit 379b206

Please sign in to comment.
Something went wrong with that request. Please try again.