Skip to content

Commit ee08554

Browse files
authored
Merge pull request #2798 from calebschoepp/needless-get-store
Prevent needlessly opening the default store
2 parents 93de36a + b21cca7 commit ee08554

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

crates/runtime-config/src/lib.rs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
33
use anyhow::Context as _;
44
use spin_common::ui::quoted_path;
55
use spin_factor_key_value::runtime_config::spin::{self as key_value};
6-
use spin_factor_key_value::{DefaultLabelResolver as _, KeyValueFactor};
6+
use spin_factor_key_value::KeyValueFactor;
77
use spin_factor_llm::{spin as llm, LlmFactor};
88
use spin_factor_outbound_http::OutboundHttpFactor;
99
use spin_factor_outbound_mqtt::OutboundMqttFactor;
@@ -156,33 +156,6 @@ where
156156
})
157157
}
158158

159-
/// Set initial key-value pairs supplied in the CLI arguments in the default store.
160-
pub async fn set_initial_key_values(
161-
&self,
162-
initial_key_values: impl IntoIterator<Item = &(String, String)>,
163-
) -> anyhow::Result<()> {
164-
// We don't want to unnecessarily interact with the default store
165-
let mut iter = initial_key_values.into_iter().peekable();
166-
if iter.peek().is_none() {
167-
return Ok(());
168-
}
169-
170-
let store = self
171-
.key_value_resolver
172-
.default(DEFAULT_KEY_VALUE_STORE_LABEL)
173-
.expect("trigger was misconfigured and lacks a default store")
174-
.get(DEFAULT_KEY_VALUE_STORE_LABEL)
175-
.await
176-
.expect("trigger was misconfigured and lacks a default store");
177-
for (key, value) in iter {
178-
store
179-
.set(key, value.as_bytes())
180-
.await
181-
.context("failed to set key-value pair")?;
182-
}
183-
Ok(())
184-
}
185-
186159
/// The fully resolved state directory.
187160
pub fn state_dir(&self) -> Option<PathBuf> {
188161
self.state_dir.clone()

crates/trigger/src/cli/initial_kv_setter.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ impl<F: RuntimeFactors, U> ExecutorHooks<F, U> for InitialKvSetterHook {
2323
&mut self,
2424
configured_app: &spin_factors::ConfiguredApp<F>,
2525
) -> anyhow::Result<()> {
26-
let Some(kv) = configured_app.app_state::<KeyValueFactor>().ok() else {
26+
if self.kv_pairs.is_empty() {
2727
return Ok(());
28-
};
28+
}
29+
let kv = configured_app.app_state::<KeyValueFactor>().context(
30+
"attempted to set initial kv pairs but the key-value factor was not configured",
31+
)?;
2932
let store = kv
3033
.get_store(DEFAULT_KEY_VALUE_STORE_LABEL)
3134
.await

0 commit comments

Comments
 (0)