持久化认证状态到 SpacetimeDB 正式表
This commit is contained in:
@@ -217,6 +217,8 @@ impl AppState {
|
||||
self.spacetime_client
|
||||
.upsert_auth_store_snapshot(snapshot_json, updated_at_micros)
|
||||
.await?;
|
||||
// ?????????????????????????????????
|
||||
self.spacetime_client.import_auth_store_snapshot().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -229,19 +231,38 @@ impl AppState {
|
||||
token: config.spacetime_token.clone(),
|
||||
pool_size: config.spacetime_pool_size,
|
||||
});
|
||||
match spacetime_client
|
||||
.export_auth_store_snapshot_from_tables()
|
||||
.await
|
||||
{
|
||||
Ok(snapshot) => {
|
||||
if let Some(snapshot_json) = snapshot.snapshot_json {
|
||||
if !snapshot_json.trim().is_empty() {
|
||||
let auth_store = InMemoryAuthStore::from_snapshot_json(&snapshot_json)
|
||||
.map_err(AppStateInitError::AuthStore)?;
|
||||
info!("?? SpacetimeDB ???????????");
|
||||
return Self::new_with_auth_store(config, auth_store);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
warn!(error = %error, "? SpacetimeDB ????????????????");
|
||||
}
|
||||
}
|
||||
|
||||
match spacetime_client.get_auth_store_snapshot().await {
|
||||
Ok(snapshot) => {
|
||||
if let Some(snapshot_json) = snapshot.snapshot_json {
|
||||
if !snapshot_json.trim().is_empty() {
|
||||
let auth_store = InMemoryAuthStore::from_snapshot_json(&snapshot_json)
|
||||
.map_err(AppStateInitError::AuthStore)?;
|
||||
info!("已从 SpacetimeDB 恢复认证快照");
|
||||
info!("?? SpacetimeDB ???????????");
|
||||
return Self::new_with_auth_store(config, auth_store);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
warn!(error = %error, "从 SpacetimeDB 恢复认证快照失败,回退到本地快照");
|
||||
warn!(error = %error, "? SpacetimeDB ?????????????????");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user