diff --git a/backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs b/backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs index 43cc59b1d..7f361d06f 100644 --- a/backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs +++ b/backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs @@ -153,11 +153,8 @@ impl FlowCcInstApi { ctx: TardisContextExtractor, _request: &Request, ) -> TardisApiResult { - let mut funs = flow_constants::get_tardis_inst(); - funs.begin().await?; let vars = HashMap::from([("current_assigned".to_string(), Value::String(modify_req.0.current_assigned))]); - FlowInstServ::modify_current_vars(&flow_inst_id.0, &vars, &funs, &ctx.0).await?; - funs.commit().await?; + FlowInstServ::modify_current_vars(&flow_inst_id.0, &vars, &ctx.0).await?; TardisResp::ok(Void {}) } @@ -172,9 +169,7 @@ impl FlowCcInstApi { _request: &Request, ) -> TardisApiResult { let mut funs = flow_constants::get_tardis_inst(); - funs.begin().await?; - FlowInstServ::modify_current_vars(&flow_inst_id.0, &modify_req.0.vars, &funs, &ctx.0).await?; - funs.commit().await?; + FlowInstServ::modify_current_vars(&flow_inst_id.0, &modify_req.0.vars, &ctx.0).await?; TardisResp::ok(Void {}) } } diff --git a/backend/middlewares/flow/src/api/ci/flow_ci_inst_api.rs b/backend/middlewares/flow/src/api/ci/flow_ci_inst_api.rs index 93cfac9d8..a0306a4ec 100644 --- a/backend/middlewares/flow/src/api/ci/flow_ci_inst_api.rs +++ b/backend/middlewares/flow/src/api/ci/flow_ci_inst_api.rs @@ -122,12 +122,10 @@ impl FlowCiInstApi { mut ctx: TardisContextExtractor, request: &Request, ) -> TardisApiResult { - let mut funs = flow_constants::get_tardis_inst(); + let funs = flow_constants::get_tardis_inst(); check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?; - funs.begin().await?; let vars = HashMap::from([("assigned_to".to_string(), Value::String(modify_req.0.current_assigned))]); - FlowInstServ::modify_current_vars(&flow_inst_id.0, &vars, &funs, &ctx.0).await?; - funs.commit().await?; + FlowInstServ::modify_current_vars(&flow_inst_id.0, &vars, &ctx.0).await?; TardisResp::ok(Void {}) } @@ -140,11 +138,9 @@ impl FlowCiInstApi { mut ctx: TardisContextExtractor, request: &Request, ) -> TardisApiResult { - let mut funs = flow_constants::get_tardis_inst(); + let funs = flow_constants::get_tardis_inst(); check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?; - funs.begin().await?; FlowInstServ::modify_current_vars(&flow_inst_id.0, &modify_req.0.vars, &funs, &ctx.0).await?; - funs.commit().await?; TardisResp::ok(Void {}) } diff --git a/backend/middlewares/flow/src/serv/flow_inst_serv.rs b/backend/middlewares/flow/src/serv/flow_inst_serv.rs index da09c5acb..e671a17ef 100644 --- a/backend/middlewares/flow/src/serv/flow_inst_serv.rs +++ b/backend/middlewares/flow/src/serv/flow_inst_serv.rs @@ -1103,7 +1103,9 @@ impl FlowInstServ { } } - pub async fn modify_current_vars(flow_inst_id: &str, current_vars: &HashMap, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { + pub async fn modify_current_vars(flow_inst_id: &str, current_vars: &HashMap, ctx: &TardisContext) -> TardisResult<()> { + let mut funs = flow_constants::get_tardis_inst(); + funs.begin().await?; let flow_inst_detail = Self::get(flow_inst_id, funs, ctx).await?; let mut new_vars: HashMap = HashMap::new(); if let Some(old_current_vars) = &flow_inst_detail.current_vars { @@ -1116,7 +1118,9 @@ impl FlowInstServ { ..Default::default() }; funs.db().update_one(flow_inst, ctx).await.unwrap(); + funs.commit().await?; + let funs = flow_constants::get_tardis_inst(); if let Some(ws_client) = ws_flow_client().await { ws_client .publish_front_change( @@ -1127,7 +1131,7 @@ impl FlowInstServ { ) .await?; } else { - FlowEventServ::do_front_change(flow_inst_id, ctx, funs).await?; + FlowEventServ::do_front_change(flow_inst_id, ctx, &funs).await?; } Ok(()) @@ -1214,7 +1218,6 @@ impl FlowInstServ { Self::modify_current_vars( &flow_inst.id, &TardisFuns::json.json_to_obj::>(new_vars).unwrap_or_default(), - funs, &ctx, ) .await?; @@ -1228,7 +1231,7 @@ impl FlowInstServ { let mut current_vars = Self::get(inst_id, funs, ctx).await?.current_vars; if current_vars.is_none() || !current_vars.clone().unwrap_or_default().contains_key(key) { let new_vars = Self::get_new_vars(inst_id, funs, ctx).await?; - Self::modify_current_vars(inst_id, &TardisFuns::json.json_to_obj::>(new_vars).unwrap_or_default(), funs, ctx).await?; + Self::modify_current_vars(inst_id, &TardisFuns::json.json_to_obj::>(new_vars).unwrap_or_default(), ctx).await?; current_vars = Self::get(inst_id, funs, ctx).await?.current_vars; }