From 1fac7046d69106885c1ebab4664b0ad77406d0cb Mon Sep 17 00:00:00 2001 From: Avery Harnish Date: Mon, 11 May 2020 11:24:43 -0500 Subject: [PATCH] removes redundant builds when watching --- src/commands/build/watch/mod.rs | 5 ++++- src/commands/dev/gcs/mod.rs | 3 +++ src/commands/dev/gcs/watch.rs | 1 - src/commands/dev/mod.rs | 4 ---- src/commands/preview/mod.rs | 4 +--- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/commands/build/watch/mod.rs b/src/commands/build/watch/mod.rs index 0f1aeef06..01edd5c27 100644 --- a/src/commands/build/watch/mod.rs +++ b/src/commands/build/watch/mod.rs @@ -45,7 +45,10 @@ pub fn watch_and_build( tx.send(()).expect("--watch change message failed to send"); } } - Err(_) => message::user_error("Something went wrong while watching."), + Err(e) => { + log::debug!("{:?}", e); + message::user_error("Something went wrong while watching.") + } } } }); diff --git a/src/commands/dev/gcs/mod.rs b/src/commands/dev/gcs/mod.rs index 343fc91c2..c0ec4f304 100644 --- a/src/commands/dev/gcs/mod.rs +++ b/src/commands/dev/gcs/mod.rs @@ -27,6 +27,9 @@ pub fn dev( // setup the session let session_id = get_session_id()?; + // build once before starting + commands::build(&target)?; + // upload the initial script let preview_id = get_preview_id( target.clone(), diff --git a/src/commands/dev/gcs/watch.rs b/src/commands/dev/gcs/watch.rs index 428038930..533584d96 100644 --- a/src/commands/dev/gcs/watch.rs +++ b/src/commands/dev/gcs/watch.rs @@ -21,7 +21,6 @@ pub fn watch_for_changes( while let Ok(_) = receiver.recv() { let user = user.clone(); let target = target.clone(); - commands::build(&target)?; // acquire the lock so incoming requests are halted // until the new script is ready for them diff --git a/src/commands/dev/mod.rs b/src/commands/dev/mod.rs index 2c8635cdc..4406fcbbc 100644 --- a/src/commands/dev/mod.rs +++ b/src/commands/dev/mod.rs @@ -3,7 +3,6 @@ mod server_config; mod socket; use server_config::ServerConfig; -use crate::commands; use crate::settings::global_user::GlobalUser; use crate::settings::toml::Target; use crate::terminal::{message, styles}; @@ -23,9 +22,6 @@ pub fn dev( // we can remove this once the feature has stabilized print_alpha_warning_message(); - // before serving requests we must first build the Worker - commands::build(&target)?; - // eventually we will have two modes - edge and gcs // edge for authenticated users and gcs for unauthenticated // for now, always route to gcs diff --git a/src/commands/preview/mod.rs b/src/commands/preview/mod.rs index f0d401edd..27058c40a 100644 --- a/src/commands/preview/mod.rs +++ b/src/commands/preview/mod.rs @@ -169,9 +169,7 @@ fn watch_for_changes( let (tx, rx) = channel(); commands::watch_and_build(&target, Some(tx))?; - while let Ok(_e) = rx.recv() { - commands::build(&target)?; - + while let Ok(_) = rx.recv() { if let Ok(new_id) = upload(&mut target, user, sites_preview, verbose) { let script_id = format!("{}", new_id);