Skip to content

Commit

Permalink
Merge pull request #2798 from calebschoepp/needless-get-store
Browse files Browse the repository at this point in the history
Prevent needlessly opening the default store
  • Loading branch information
michelleN committed Sep 5, 2024
2 parents 93de36a + b21cca7 commit ee08554
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
29 changes: 1 addition & 28 deletions crates/runtime-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Item = &(String, String)>,
) -> 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<PathBuf> {
self.state_dir.clone()
Expand Down
7 changes: 5 additions & 2 deletions crates/trigger/src/cli/initial_kv_setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ impl<F: RuntimeFactors, U> ExecutorHooks<F, U> for InitialKvSetterHook {
&mut self,
configured_app: &spin_factors::ConfiguredApp<F>,
) -> anyhow::Result<()> {
let Some(kv) = configured_app.app_state::<KeyValueFactor>().ok() else {
if self.kv_pairs.is_empty() {
return Ok(());
};
}
let kv = configured_app.app_state::<KeyValueFactor>().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
Expand Down

0 comments on commit ee08554

Please sign in to comment.