From b21cca7b9bf498019d945cc55054033c8e050f10 Mon Sep 17 00:00:00 2001 From: Caleb Schoepp Date: Wed, 4 Sep 2024 12:29:44 -0600 Subject: [PATCH] Prevent needlessly opening the default store Signed-off-by: Caleb Schoepp --- crates/runtime-config/src/lib.rs | 29 +-------------------- crates/trigger/src/cli/initial_kv_setter.rs | 7 +++-- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/crates/runtime-config/src/lib.rs b/crates/runtime-config/src/lib.rs index e37afa4656..3b7b8039b6 100644 --- a/crates/runtime-config/src/lib.rs +++ b/crates/runtime-config/src/lib.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use anyhow::Context as _; use spin_common::ui::quoted_path; use spin_factor_key_value::runtime_config::spin::{self as key_value}; -use spin_factor_key_value::{DefaultLabelResolver as _, KeyValueFactor}; +use spin_factor_key_value::KeyValueFactor; use spin_factor_llm::{spin as llm, LlmFactor}; use spin_factor_outbound_http::OutboundHttpFactor; use spin_factor_outbound_mqtt::OutboundMqttFactor; @@ -156,33 +156,6 @@ where }) } - /// Set initial key-value pairs supplied in the CLI arguments in the default store. - pub async fn set_initial_key_values( - &self, - initial_key_values: impl IntoIterator, - ) -> anyhow::Result<()> { - // We don't want to unnecessarily interact with the default store - let mut iter = initial_key_values.into_iter().peekable(); - if iter.peek().is_none() { - return Ok(()); - } - - let store = self - .key_value_resolver - .default(DEFAULT_KEY_VALUE_STORE_LABEL) - .expect("trigger was misconfigured and lacks a default store") - .get(DEFAULT_KEY_VALUE_STORE_LABEL) - .await - .expect("trigger was misconfigured and lacks a default store"); - for (key, value) in iter { - store - .set(key, value.as_bytes()) - .await - .context("failed to set key-value pair")?; - } - Ok(()) - } - /// The fully resolved state directory. pub fn state_dir(&self) -> Option { self.state_dir.clone() diff --git a/crates/trigger/src/cli/initial_kv_setter.rs b/crates/trigger/src/cli/initial_kv_setter.rs index fad119daea..d1fc31e127 100644 --- a/crates/trigger/src/cli/initial_kv_setter.rs +++ b/crates/trigger/src/cli/initial_kv_setter.rs @@ -23,9 +23,12 @@ impl ExecutorHooks for InitialKvSetterHook { &mut self, configured_app: &spin_factors::ConfiguredApp, ) -> anyhow::Result<()> { - let Some(kv) = configured_app.app_state::().ok() else { + if self.kv_pairs.is_empty() { return Ok(()); - }; + } + let kv = configured_app.app_state::().context( + "attempted to set initial kv pairs but the key-value factor was not configured", + )?; let store = kv .get_store(DEFAULT_KEY_VALUE_STORE_LABEL) .await