perf: read gallery hot paths from spacetime cache
This commit is contained in:
@@ -3,6 +3,49 @@ use super::*;
|
||||
impl SpacetimeClient {
|
||||
pub async fn get_creation_entry_config(
|
||||
&self,
|
||||
) -> Result<CreationEntryConfigRecord, SpacetimeClientError> {
|
||||
match self
|
||||
.read_after_connect(move |connection| {
|
||||
let config_id = module_runtime::CREATION_ENTRY_CONFIG_GLOBAL_ID.to_string();
|
||||
let header = connection
|
||||
.db()
|
||||
.creation_entry_config()
|
||||
.config_id()
|
||||
.find(&config_id)
|
||||
.ok_or_else(|| SpacetimeClientError::missing_snapshot("创作入口配置快照"))?;
|
||||
let creation_types = connection
|
||||
.db()
|
||||
.creation_entry_type_config()
|
||||
.iter()
|
||||
.collect::<Vec<_>>();
|
||||
Ok(build_creation_entry_config_record_from_rows(
|
||||
header,
|
||||
creation_types,
|
||||
))
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(config) => {
|
||||
self.cache_creation_entry_config(config.clone()).await;
|
||||
Ok(config)
|
||||
}
|
||||
Err(_) => {
|
||||
if let Some(config) = self.read_cached_creation_entry_config().await {
|
||||
return Ok(config);
|
||||
}
|
||||
match self.fetch_creation_entry_config_via_procedure().await {
|
||||
Ok(config) => {
|
||||
self.cache_creation_entry_config(config.clone()).await;
|
||||
Ok(config)
|
||||
}
|
||||
Err(fallback_error) => Err(fallback_error),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn fetch_creation_entry_config_via_procedure(
|
||||
&self,
|
||||
) -> Result<CreationEntryConfigRecord, SpacetimeClientError> {
|
||||
self.call_after_connect("get_creation_entry_config", move |connection, sender| {
|
||||
connection
|
||||
@@ -22,20 +65,26 @@ impl SpacetimeClient {
|
||||
input: module_runtime::CreationEntryTypeAdminUpsertInput,
|
||||
) -> Result<CreationEntryConfigRecord, SpacetimeClientError> {
|
||||
let procedure_input: CreationEntryTypeAdminUpsertInput = input.into();
|
||||
self.call_after_connect(
|
||||
"upsert_creation_entry_type_config",
|
||||
move |connection, sender| {
|
||||
connection
|
||||
.procedures()
|
||||
.upsert_creation_entry_type_config_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(SpacetimeClientError::from_sdk_error)
|
||||
.and_then(map_creation_entry_config_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
});
|
||||
},
|
||||
)
|
||||
.await
|
||||
let config = self
|
||||
.call_after_connect(
|
||||
"upsert_creation_entry_type_config",
|
||||
move |connection, sender| {
|
||||
connection
|
||||
.procedures()
|
||||
.upsert_creation_entry_type_config_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(SpacetimeClientError::from_sdk_error)
|
||||
.and_then(map_creation_entry_config_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
},
|
||||
);
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
self.cache_creation_entry_config(config.clone()).await;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
pub async fn get_runtime_settings(
|
||||
|
||||
Reference in New Issue
Block a user