From 6c8403aa1dcdec39701e309e7fae6ca92aaff135 Mon Sep 17 00:00:00 2001
From: greg1anderson <greg.1.anderson@greenknowe.org>
Date: Thu, 3 Mar 2011 10:12:02 -0800
Subject: [PATCH] #1069372 by greg1anderson, jazzslider, msonnabaum: Optimize bootstrap by making a new "max_validate" handler only called during bootstrap_max

---
 includes/environment.inc |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/includes/environment.inc b/includes/environment.inc
index 7e0894b..4a423aa 100644
--- a/includes/environment.inc
+++ b/includes/environment.inc
@@ -252,7 +252,7 @@ function drush_has_boostrapped($phase) {
  *   True if bootstrap is possible, False if the validation failed.
  *
  */
-function drush_bootstrap_validate($phase) {
+function drush_bootstrap_validate($phase, $max_validate = FALSE) {
   static $phases;
   static $result_cache = array();
   if (!$phases) {
@@ -266,7 +266,7 @@ function drush_bootstrap_validate($phase) {
     while ($phase >= $phase_index && isset($phases[$phase_index])) {
       $current_phase = $phases[$phase_index] . '_validate';
       if (function_exists($current_phase)) {
-        $result_cache[$phase_index] = $current_phase();
+        $result_cache[$phase_index] = $current_phase($max_validate);
       }
       else {
         $result_cache[$phase_index] = TRUE;
@@ -338,7 +338,7 @@ function drush_bootstrap_max($max_phase_index = FALSE) {
       break;
     }
 
-    if (drush_bootstrap_validate($phase_index)) {
+    if (drush_bootstrap_validate($phase_index, TRUE)) {
       if ($phase_index > drush_get_context('DRUSH_BOOTSTRAP_PHASE')) {
         drush_bootstrap($phase_index, $max_phase_index);
       }
@@ -497,7 +497,7 @@ function _drush_environment_check_php_ini() {
 /**
  * Validate that Drush is running in a suitable environment.
  */
-function _drush_bootstrap_drush_validate() {
+function _drush_bootstrap_drush_validate($max_validate = FALSE) {
   // @todo _drush_environment_php_ini_checks() always returns TRUE.
   $return = _drush_environment_check_php_ini();
   if ($return !== TRUE) {
@@ -684,7 +684,7 @@ function _drush_bootstrap_global_options() {
  * We also determine the value that will be stored in the DRUSH_DRUPAL_ROOT
  * context and DRUPAL_ROOT constant if it is considered a valid option.
  */
-function _drush_bootstrap_drupal_root_validate() {
+function _drush_bootstrap_drupal_root_validate($max_validate = FALSE) {
   $drupal_root = drush_get_option(array('r', 'root'), drush_locate_root());
 
   if (empty($drupal_root)) {
@@ -740,7 +740,7 @@ function _drush_bootstrap_drupal_root() {
  * to allow us to use conf_path to determine what Drupal will load
  * as a configuration file.
  */
-function _drush_bootstrap_drupal_site_validate() {
+function _drush_bootstrap_drupal_site_validate($max_validate = FALSE) {
   $site_path = drush_site_path();
   $elements = explode('/', $site_path);
   $current = array_pop($elements);
@@ -933,7 +933,7 @@ function _drush_bootstrap_drupal_configuration() {
  * database credentials that were loaded during the previous
  * phase.
  */
-function _drush_bootstrap_drupal_database_validate() {
+function _drush_bootstrap_drupal_database_validate($max_validate = FALSE) {
   if (!drush_valid_db_credentials()) {
     return drush_bootstrap_error('DRUSH_DRUPAL_DB_ERROR');
   }
@@ -953,15 +953,21 @@ function _drush_bootstrap_drupal_database() {
 /**
  * Validate the DRUSH_BOOTSTRAP_DRUPAL_FULL phase
  *
- * Check to see if the database contains any tables.
+ * Check to see if the install_task variable is "done".
  */
-function _drush_bootstrap_drupal_full_validate() {
-  $result = _drush_sql_query_execute('show tables;');
-  $lines = drush_shell_exec_output();
-  if (count($lines) <= 0) {
-    return drush_bootstrap_error('DRUSH_DRUPAL_DB_ERROR');
+function _drush_bootstrap_drupal_full_validate($max_validate = FALSE) {
+  if ($max_validate === FALSE) {
+    return TRUE;
   }
-  return TRUE;
+  
+  $result = @db_query("SELECT value FROM {variable} WHERE name = '%s'", 'install_task');
+  if ($result) {
+    $result = unserialize(db_result($result));
+    if ($result == 'done') {
+      return TRUE;
+    }
+  }
+  return drush_bootstrap_error('DRUSH_DRUPAL_DB_ERROR');
 }
 
 /**
-- 
1.7.1

