mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-09-15 06:11:48 +02:00
Route all database writes through one connection (#642)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
ff7eebf3cd
commit
90cb578e26
@@ -72,7 +72,7 @@ pub trait Host: Clone {
|
||||
self.query_manager().connect()
|
||||
}
|
||||
|
||||
fn blobs(&self) -> BlobContext {
|
||||
fn blobs(&self) -> BlobContext<'_> {
|
||||
self.blob_manager().connect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,11 @@ use yaak_models::queries::workspaces::default_headers;
|
||||
use yaak_rpc_schema::*;
|
||||
|
||||
pub async fn models_upsert<H: Host>(host: H, req: ModelsUpsertReq) -> Result<String> {
|
||||
let db = host.db();
|
||||
let blobs = host.blob_manager();
|
||||
let source = host.update_source();
|
||||
Ok(yaak_models::models_ops::upsert_model(&db, blobs, req.model, &source)?)
|
||||
Ok(host
|
||||
.query_manager()
|
||||
.with_tx(|tx| yaak_models::models_ops::upsert_model(tx, blobs, req.model, &source))?)
|
||||
}
|
||||
|
||||
/// Deletes cascade — a workspace can hold thousands of requests — and run in a
|
||||
@@ -75,12 +76,9 @@ pub async fn models_upsert_graphql_introspection<H: Host>(
|
||||
req: ModelsUpsertGraphqlIntrospectionReq,
|
||||
) -> Result<GraphQlIntrospection> {
|
||||
let source = host.update_source();
|
||||
Ok(host.db().upsert_graphql_introspection(
|
||||
&req.workspace_id,
|
||||
&req.request_id,
|
||||
req.content,
|
||||
&source,
|
||||
)?)
|
||||
Ok(host.query_manager().with_tx(|tx| {
|
||||
tx.upsert_graphql_introspection(&req.workspace_id, &req.request_id, req.content, &source)
|
||||
})?)
|
||||
}
|
||||
|
||||
/// Everything the frontend's model store needs to boot, as one JSON string.
|
||||
@@ -112,9 +110,16 @@ pub async fn models_workspace_models<H: PluginHost>(
|
||||
|
||||
// Add the workspace children
|
||||
if let Some(wid) = req.workspace_id.as_deref() {
|
||||
// Opening a workspace is where the rows it is assumed to have get created
|
||||
host.query_manager().with_tx(|tx| {
|
||||
tx.ensure_base_environment(wid)?;
|
||||
tx.ensure_default_cookie_jar(wid)?;
|
||||
tx.ensure_workspace_meta(wid)?;
|
||||
Ok::<(), yaak_models::error::Error>(())
|
||||
})?;
|
||||
let db = host.db();
|
||||
l.append(&mut db.list_cookie_jars(wid)?.into_iter().map(Into::into).collect());
|
||||
l.append(&mut db.list_environments_ensure_base(wid)?.into_iter().map(Into::into).collect());
|
||||
l.append(&mut db.list_environments(wid)?.into_iter().map(Into::into).collect());
|
||||
l.append(&mut db.list_folders(wid)?.into_iter().map(Into::into).collect());
|
||||
l.append(&mut db.list_grpc_connections(wid)?.into_iter().map(Into::into).collect());
|
||||
l.append(&mut db.list_grpc_requests(wid)?.into_iter().map(Into::into).collect());
|
||||
@@ -132,23 +137,26 @@ pub async fn cmd_get_workspace_meta<H: Host>(
|
||||
host: H,
|
||||
req: CmdGetWorkspaceMetaReq,
|
||||
) -> Result<WorkspaceMeta> {
|
||||
let db = host.db();
|
||||
let workspace = db.get_workspace(&req.workspace_id)?;
|
||||
Ok(db.get_or_create_workspace_meta(&workspace.id)?)
|
||||
let workspace = host.db().get_workspace(&req.workspace_id)?;
|
||||
Ok(host.query_manager().with_tx(|tx| tx.ensure_workspace_meta(&workspace.id))?)
|
||||
}
|
||||
|
||||
pub async fn cmd_delete_all_grpc_connections<H: Host>(
|
||||
host: H,
|
||||
req: CmdDeleteAllGrpcConnectionsReq,
|
||||
) -> Result<()> {
|
||||
Ok(host.db().delete_all_grpc_connections_for_request(&req.request_id, &host.update_source())?)
|
||||
Ok(host.query_manager().with_tx(|tx| {
|
||||
tx.delete_all_grpc_connections_for_request(&req.request_id, &host.update_source())
|
||||
})?)
|
||||
}
|
||||
|
||||
pub async fn cmd_delete_all_http_responses<H: Host>(
|
||||
host: H,
|
||||
req: CmdDeleteAllHttpResponsesReq,
|
||||
) -> Result<()> {
|
||||
host.db().delete_all_http_responses_for_request(&req.request_id, &host.update_source())?;
|
||||
host.query_manager().with_tx(|tx| {
|
||||
tx.delete_all_http_responses_for_request(&req.request_id, &host.update_source())
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -156,9 +164,9 @@ pub async fn cmd_ws_delete_connections<H: Host>(
|
||||
host: H,
|
||||
req: CmdWsDeleteConnectionsReq,
|
||||
) -> Result<()> {
|
||||
Ok(host
|
||||
.db()
|
||||
.delete_all_websocket_connections_for_request(&req.request_id, &host.update_source())?)
|
||||
Ok(host.query_manager().with_tx(|tx| {
|
||||
tx.delete_all_websocket_connections_for_request(&req.request_id, &host.update_source())
|
||||
})?)
|
||||
}
|
||||
|
||||
pub async fn cmd_delete_send_history<H: Host>(host: H, req: CmdDeleteSendHistoryReq) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user