Skip to content

optimize: using subqueries to reduce the retrieval of invalid content data. #7184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public StateMachine getStateMachineById(String stateMachineId) {

@Override
public StateMachine getLastVersionStateMachine(String stateMachineName, String tenantId) {
List<StateMachine> list = selectList(stateLangStoreSqls.getQueryStateMachinesByNameAndTenantSql(dbType),
RESULT_SET_TO_STATE_MACHINE, stateMachineName, tenantId);
List<StateMachine> list = selectList(stateLangStoreSqls.getLastVersionStateMachine(dbType),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this change been fully tested by saga? I remember that tenant_id is an optional field, what happens if the upper layer doesn't pass the tenant_id parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this change been fully tested by saga? I remember that tenant_id is an optional field, what happens if the upper layer doesn't pass the tenant_id parameter?

I've performed local testing and executed the Saga test approach. When the tenant_id parameter is not provided, the system will automatically fill it with the defaultTenantId (000001).
image

RESULT_SET_TO_STATE_MACHINE, stateMachineName, tenantId, stateMachineName, tenantId);
if (CollectionUtils.isNotEmpty(list)) {
return list.get(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ public class StateLangStoreSqls {
private static final String INSERT_STATE_MACHINE_SQL = "INSERT INTO ${TABLE_PREFIX}state_machine_def ("
+ STATE_MACHINE_FIELDS + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

private static final String GET_LAST_VERSION_STATE_MACHINE_SQL = "SELECT " + STATE_MACHINE_FIELDS
+ " FROM ${TABLE_PREFIX}state_machine_def WHERE name = ? AND tenant_id = ? " +
"AND gmt_create = ( SELECT MAX(gmt_create) FROM ${TABLE_PREFIX}state_machine_def WHERE name = ? AND tenant_id = ? )";

private static final String TABLE_PREFIX_REGEX = "\\$\\{TABLE_PREFIX}";

private String tablePrefix;

private String getGetStateMachineByIdSql;
private String queryStateMachinesByNameAndTenantSql;
private String insertStateMachineSql;
private String getLastVersionStateMachine;

public StateLangStoreSqls(String tablePrefix) {
this.tablePrefix = tablePrefix;
Expand All @@ -52,6 +57,7 @@ private void init() {
queryStateMachinesByNameAndTenantSql = QUERY_STATE_MACHINES_BY_NAME_AND_TENANT_SQL.replaceAll(
TABLE_PREFIX_REGEX, tablePrefix);
insertStateMachineSql = INSERT_STATE_MACHINE_SQL.replaceAll(TABLE_PREFIX_REGEX, tablePrefix);
getLastVersionStateMachine = GET_LAST_VERSION_STATE_MACHINE_SQL.replaceAll(TABLE_PREFIX_REGEX, tablePrefix);
}

public String getGetStateMachineByIdSql(String dbType) {
Expand All @@ -62,6 +68,10 @@ public String getQueryStateMachinesByNameAndTenantSql(String dbType) {
return queryStateMachinesByNameAndTenantSql;
}

public String getLastVersionStateMachine(String dbType) {
return getLastVersionStateMachine;
}

public String getInsertStateMachineSql(String dbType) {
return insertStateMachineSql;
}
Expand Down
Loading