Index: modules/taxonomy/taxonomy.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.admin.inc,v
retrieving revision 1.9
diff -u -r1.9 taxonomy.admin.inc
--- modules/taxonomy/taxonomy.admin.inc	20 Nov 2007 15:31:34 -0000	1.9
+++ modules/taxonomy/taxonomy.admin.inc	21 Nov 2007 21:12:06 -0000
@@ -275,17 +275,24 @@
     '#collapsed' => TRUE,
   );
 
-  $parent = array_keys(taxonomy_get_parents($edit['tid']));
-  $children = taxonomy_get_tree($vocabulary->vid, $edit['tid']);
+/** taxonomy_get_tree and taxonomy_get_parents may contain large numbers of
+  * itemsso we check for taxonomy_override_selector before loading the full
+  * vocabulary, so contrib modules can intercept before hook_form_alter to
+  * provide scalable alternatives.
+  */
+  if (variable_get('menu_override_parent_selector', FALSE)) {
+    $parent = array_keys(taxonomy_get_parents($edit['tid']));
+    $children = taxonomy_get_tree($vocabulary->vid, $edit['tid']);
+
+    // A term can't be the child of itself, nor of its children.
+    foreach ($children as $child) {
+      $exclude[] = $child->tid;
+    }
+    $exclude[] = $edit['tid'];
 
-  // A term can't be the child of itself, nor of its children.
-  foreach ($children as $child) {
-    $exclude[] = $child->tid;
+    $form['advanced']['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary->vid, t('Parent terms') .'.', 1, '<'. t('root') .'>', $exclude);
+    $form['advanced']['relations'] = _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary->vid, NULL, 1, '<'. t('none') .'>', array($edit['tid']));
   }
-  $exclude[] = $edit['tid'];
-
-  $form['advanced']['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary->vid, t('Parent terms') .'.', 1, '<'. t('root') .'>', $exclude);
-
   $form['advanced']['synonyms'] = array(
     '#type' => 'textarea',
     '#title' => t('Synonyms'),
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.395
diff -u -r1.395 taxonomy.module
--- modules/taxonomy/taxonomy.module	20 Nov 2007 15:53:59 -0000	1.395
+++ modules/taxonomy/taxonomy.module	21 Nov 2007 20:59:52 -0000
@@ -428,9 +428,12 @@
 /**
  * Implementation of hook_form_alter().
  * Generate a form for selecting terms to associate with a node.
+ * We check for taxonomy_override_selector before loading the full vocabulary,
+ * so contrib modules can intercept before hook_form_alter and provide scalable
+ * alternatives.
  */
 function taxonomy_form_alter(&$form, $form_state, $form_id) {
-  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
+  if (isset($form['type']) && isset($form['#node']) && (variable_get('taxonomy_override_selector', FALSE)) && $form['type']['#value'] .'_node_form' == $form_id) {
     $node = $form['#node'];
 
     if (!isset($node->taxonomy)) {
