Skip to content

Commit

Permalink
flow: optimize response time (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Nov 28, 2023
1 parent 85a1415 commit cbef639
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 40 deletions.
1 change: 1 addition & 0 deletions middleware/flow/src/dto/flow_model_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub struct FlowModelFilterReq {
pub rel_template_id: Option<String>,
pub template: Option<bool>,
pub own_paths: Option<Vec<String>>,
pub specified_state_ids: Option<Vec<String>>,
}

impl RbumItemFilterFetcher for FlowModelFilterReq {
Expand Down
9 changes: 2 additions & 7 deletions middleware/flow/src/flow_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use bios_sdk_invoke::invoke_initializer;

use tardis::{
basic::{dto::TardisContext, field::TrimString, result::TardisResult},
db::{
reldb_client::TardisActiveModel,
sea_orm::sea_query::Table,
},
db::{reldb_client::TardisActiveModel, sea_orm::sea_query::Table},
log::info,
web::web_server::TardisWebServer,
TardisFuns, TardisFunsInst,
Expand All @@ -27,9 +24,7 @@ use crate::{
dto::{
flow_model_dto::FlowModelFilterReq,
flow_state_dto::FlowSysStateKind,
flow_transition_dto::{
FlowTransitionDoubleCheckInfo, FlowTransitionInitInfo,
},
flow_transition_dto::{FlowTransitionDoubleCheckInfo, FlowTransitionInitInfo},
},
flow_config::{BasicInfo, FlowBasicInfoManager, FlowConfig},
flow_constants,
Expand Down
3 changes: 2 additions & 1 deletion middleware/flow/src/serv/flow_config_serv.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bios_basic::rbum::rbum_enumeration::RbumScopeLevelKind;
use bios_sdk_invoke::clients::spi_kv_client::{KvItemSummaryResp, SpiKvClient};
use tardis::{
basic::{dto::TardisContext, result::TardisResult},
Expand All @@ -12,7 +13,7 @@ pub struct FlowConfigServ;
impl FlowConfigServ {
pub async fn modify_config(modify_req: &Vec<FlowConfigModifyReq>, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
for req in modify_req {
SpiKvClient::add_or_modify_item(&format!("{}:config:{}", flow_constants::DOMAIN_CODE, req.code.clone()), &req.value, None, funs, ctx).await?;
SpiKvClient::add_or_modify_item(&format!("{}:config:{}", flow_constants::DOMAIN_CODE, req.code.clone()), &req.value, None, Some(RbumScopeLevelKind::Root.to_int()), funs, ctx).await?;
}
Ok(())
}
Expand Down
26 changes: 14 additions & 12 deletions middleware/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};

use async_recursion::async_recursion;
use bios_basic::{
Expand Down Expand Up @@ -534,11 +534,12 @@ impl FlowInstServ {
let flow_models = FlowModelServ::find_detail_items(
&FlowModelFilterReq {
basic: RbumBasicFilterReq {
ids: Some(flow_insts.iter().map(|inst| inst.rel_flow_model_id.to_string()).collect_vec()),
ids: Some(flow_insts.iter().map(|inst| inst.rel_flow_model_id.to_string()).collect::<HashSet<_>>().into_iter().collect()),
with_sub_own_paths: true,
own_paths: Some("".to_string()),
..Default::default()
},
specified_state_ids: Some(flow_insts.iter().map(|inst| inst.current_state_id.clone()).collect::<HashSet<_>>().into_iter().collect()),
..Default::default()
},
None,
Expand Down Expand Up @@ -680,15 +681,7 @@ impl FlowInstServ {
}
let model_transition = flow_model.transitions();
let next_transition_detail = model_transition.iter().find(|trans| trans.id == transfer_req.flow_transition_id).unwrap().to_owned();
if FlowModelServ::check_post_action_ring(
next_transition_detail.clone(),
(false, vec![]),
funs,
ctx,
)
.await?
.0
{
if FlowModelServ::check_post_action_ring(next_transition_detail.clone(), (false, vec![]), funs, ctx).await?.0 {
return Err(funs.err().not_found("flow_inst", "transfer", "this post action exist endless loop", "500-flow-transition-endless-loop"));
}

Expand Down Expand Up @@ -821,7 +814,16 @@ impl FlowInstServ {
let post_changes =
model_transition.into_iter().find(|model_transition| model_transition.id == next_flow_transition.next_flow_transition_id).unwrap_or_default().action_by_post_changes();
if !post_changes.is_empty() {
Self::do_post_change(&flow_inst_detail, &flow_model, post_changes, updated_instance_list, next_transition_detail.is_notify, ctx, funs).await?;
Self::do_post_change(
&flow_inst_detail,
&flow_model,
post_changes,
updated_instance_list,
next_transition_detail.is_notify,
ctx,
funs,
)
.await?;
}
let next_flow_transitions = Self::do_find_next_transitions(&flow_inst_detail, &flow_model, None, &None, skip_filter, funs, ctx).await?.next_flow_transitions;

Expand Down
16 changes: 10 additions & 6 deletions middleware/flow/src/serv/flow_model_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl RbumItemCrudOperation<flow_model::ActiveModel, FlowModelAddReq, FlowModelMo

async fn get_item(flow_model_id: &str, filter: &FlowModelFilterReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<FlowModelDetailResp> {
let mut flow_model = Self::do_get_item(flow_model_id, filter, funs, ctx).await?;
let flow_transitions = Self::find_transitions(flow_model_id, funs, ctx).await?;
let flow_transitions = Self::find_transitions(flow_model_id, filter.specified_state_ids.as_deref(), funs, ctx).await?;
flow_model.transitions = Some(TardisFuns::json.obj_to_json(&flow_transitions)?);
Ok(flow_model)
}
Expand All @@ -216,7 +216,7 @@ impl RbumItemCrudOperation<flow_model::ActiveModel, FlowModelAddReq, FlowModelMo
) -> TardisResult<TardisPage<FlowModelDetailResp>> {
let mut flow_models = Self::do_paginate_detail_items(filter, page_number, page_size, desc_sort_by_create, desc_sort_by_update, funs, ctx).await?;
for flow_model in &mut flow_models.records {
let flow_transitions = Self::find_transitions(&flow_model.id, funs, ctx).await?;
let flow_transitions = Self::find_transitions(&flow_model.id, filter.specified_state_ids.as_deref(), funs, ctx).await?;
flow_model.transitions = Some(TardisFuns::json.obj_to_json(&flow_transitions)?);
}
Ok(flow_models)
Expand All @@ -231,7 +231,7 @@ impl RbumItemCrudOperation<flow_model::ActiveModel, FlowModelAddReq, FlowModelMo
) -> TardisResult<Vec<FlowModelDetailResp>> {
let mut flow_models = Self::do_find_detail_items(filter, desc_sort_by_create, desc_sort_by_update, funs, ctx).await?;
for flow_model in &mut flow_models {
let flow_transitions = Self::find_transitions(&flow_model.id, funs, ctx).await?;
let flow_transitions = Self::find_transitions(&flow_model.id, filter.specified_state_ids.as_deref(), funs, ctx).await?;
flow_model.transitions = Some(TardisFuns::json.obj_to_json(&flow_transitions)?);
}
Ok(flow_models)
Expand Down Expand Up @@ -555,7 +555,7 @@ impl FlowModelServ {
Ok(())
}

async fn find_transitions(flow_model_id: &str, funs: &TardisFunsInst, _ctx: &TardisContext) -> TardisResult<Vec<FlowTransitionDetailResp>> {
async fn find_transitions(flow_model_id: &str, specified_state_ids: Option<&[String]>, funs: &TardisFunsInst, _ctx: &TardisContext) -> TardisResult<Vec<FlowTransitionDetailResp>> {
let from_state_rbum_table = Alias::new("from_state_rbum");
let from_state_table = Alias::new("from_state");
let to_state_rbum_table = Alias::new("to_state_rbum");
Expand Down Expand Up @@ -624,7 +624,11 @@ impl FlowModelServ {
to_state_table.clone(),
Cond::all().add(Expr::col((to_state_table.clone(), ID_FIELD.clone())).equals((flow_transition::Entity, flow_transition::Column::FromFlowStateId))),
)
.and_where(Expr::col((flow_transition::Entity, flow_transition::Column::RelFlowModelId)).eq(flow_model_id))
.and_where(Expr::col((flow_transition::Entity, flow_transition::Column::RelFlowModelId)).eq(flow_model_id));
if let Some(specified_state_ids) = specified_state_ids {
query.and_where(Expr::col((flow_transition::Entity, flow_transition::Column::FromFlowStateId)).is_in(specified_state_ids));
}
query
.order_by((flow_transition::Entity, flow_transition::Column::Sort), Order::Asc)
.order_by((flow_transition::Entity, flow_transition::Column::CreateTime), Order::Asc)
.order_by((flow_transition::Entity, flow_transition::Column::Id), Order::Asc);
Expand Down Expand Up @@ -1174,7 +1178,7 @@ impl FlowModelServ {
funs: &TardisFunsInst,
ctx: &TardisContext,
) -> TardisResult<Vec<FlowTransitionDetailResp>> {
Ok(Self::find_transitions(flow_model_id, funs, ctx)
Ok(Self::find_transitions(flow_model_id, None, funs, ctx)
.await?
.into_iter()
.filter(|tran_detail| {
Expand Down
5 changes: 3 additions & 2 deletions sdk/invoke/src/clients/spi_kv_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ pub struct KvItemDetailResp {
}

impl SpiKvClient {
pub async fn add_or_modify_item<T: ?Sized + Serialize>(key: &str, value: &T, info: Option<String>, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
pub async fn add_or_modify_item<T: ?Sized + Serialize>(key: &str, value: &T, info: Option<String>, scope_level: Option<i16>, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let kv_url: String = BaseSpiClient::module_url(InvokeModuleKind::Kv, funs).await?;
let headers = BaseSpiClient::headers(None, funs, ctx).await?;
let json = json!({
"key":key.to_string(),
"value":value,
"info":info
"info":info,
"scope_level":scope_level,
});
funs.web_client().put_obj_to_str(&format!("{kv_url}/ci/item"), &json, headers.clone()).await?;
Ok(())
Expand Down
21 changes: 12 additions & 9 deletions spi/spi-kv/src/serv/pg/kv_pg_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,18 @@ WHERE
update_time: item.try_get("", "update_time")?,
})
})
.filter(|item| item.is_ok() && rbum_scope_helper::check_scope(
&item.as_ref().expect("invalid result").own_paths,
Some(item.as_ref().expect("invalid result").scope_level),
&RbumBasicFilterReq {
ignore_scope: false,
..Default::default()
},
ctx,
))
.filter(|item| {
item.is_ok()
&& rbum_scope_helper::check_scope(
&item.as_ref().expect("invalid result").own_paths,
Some(item.as_ref().expect("invalid result").scope_level),
&RbumBasicFilterReq {
ignore_scope: false,
..Default::default()
},
ctx,
)
})
.collect::<TardisResult<Vec<_>>>()?;
Ok(TardisPage {
page_size: match_req.page_size as u64,
Expand Down
2 changes: 1 addition & 1 deletion support/iam/src/console_interface/api/iam_ci_cert_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use crate::basic::dto::iam_account_dto::IamAccountExtSysResp;
use crate::basic::dto::iam_cert_dto::{IamCertAkSkAddReq, IamCertAkSkResp, IamOauth2AkSkResp, IamThirdPartyCertExtAddReq, IamCertDecodeRequest};
use crate::basic::dto::iam_cert_dto::{IamCertAkSkAddReq, IamCertAkSkResp, IamCertDecodeRequest, IamOauth2AkSkResp, IamThirdPartyCertExtAddReq};
use crate::basic::serv::iam_account_serv::IamAccountServ;
use crate::basic::serv::iam_cert_ldap_serv::IamCertLdapServ;
use crate::basic::serv::iam_cert_serv::IamCertServ;
Expand Down
2 changes: 0 additions & 2 deletions support/iam/src/console_tenant/api/iam_ct_cert_manage_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,4 @@ impl IamCtCertManageApi {
ctx.execute_task().await?;
TardisResp::ok(rbum_certs)
}


}

0 comments on commit cbef639

Please sign in to comment.