Skip to content

Commit

Permalink
fix(修复配置历史分页异常): 配置历史分页异常,所有页都是全部记录 (#9828)
Browse files Browse the repository at this point in the history
* fix(修复配置历史分页异常): 配置历史分页异常,所有页都是全部记录

* fix(修复配置历史分页异常): 修复代码格式不满足nacos要求

* fix(修复配置历史分页异常): 修复代码格式不满足nacos要求
  • Loading branch information
liu-xg authored Feb 3, 2023
1 parent a1c7def commit 65da789
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Page<ConfigHistoryInfo> findConfigHistory(String dataId, String group, St
HistoryConfigInfoMapper historyConfigInfoMapper = mapperManager.findMapper(
dataSourceService.getDataSourceType(), TableConstant.HIS_CONFIG_INFO);
String sqlCountRows = historyConfigInfoMapper.count(Arrays.asList("data_id", "group_id", "tenant_id"));
String sqlFetchRows = historyConfigInfoMapper.findConfigHistoryFetchRows();
String sqlFetchRows = historyConfigInfoMapper.pageFindConfigHistoryFetchRows(pageNo, pageSize);

PaginationHelper<ConfigHistoryInfo> helper = createPaginationHelper();
return helper.fetchPage(sqlCountRows, sqlFetchRows, new Object[] {dataId, group, tenantTmp}, pageNo, pageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public Page<ConfigHistoryInfo> findConfigHistory(String dataId, String group, St
HistoryConfigInfoMapper historyConfigInfoMapper = mapperManager.findMapper(
dataSourceService.getDataSourceType(), TableConstant.HIS_CONFIG_INFO);
String sqlCountRows = historyConfigInfoMapper.count(Arrays.asList("data_id", "group_id", "tenant_id"));
String sqlFetchRows = historyConfigInfoMapper.findConfigHistoryFetchRows();
String sqlFetchRows = historyConfigInfoMapper.pageFindConfigHistoryFetchRows(pageNo, pageSize);

Page<ConfigHistoryInfo> page = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public String removeConfigHistory() {
+ "SELECT id FROM his_config_info WHERE gmt_modified < ? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY)";
}

@Override
public String pageFindConfigHistoryFetchRows(int pageNo, int pageSize) {
final int offset = (pageNo - 1) * pageSize;
final int limit = pageSize;
return "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC OFFSET "
+ offset + " ROWS FETCH NEXT " + limit + " ROWS ONLY";
}

@Override
public String getDataSource() {
return DataSourceConstant.DERBY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public String removeConfigHistory() {
return "DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ?";
}

@Override
public String pageFindConfigHistoryFetchRows(int pageNo, int pageSize) {
final int offset = (pageNo - 1) * pageSize;
final int limit = pageSize;
return "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC LIMIT " + offset + "," + limit;
}

@Override
public String getDataSource() {
return DataSourceConstant.MYSQL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,18 @@ default String findConfigHistoryFetchRows() {
return "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC";
}


/**
* page search List configuration history.
* SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info
* WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC limit ?,?
*
* @param pageNo pageNo
* @param pageSize pageSize
* @return
*/
String pageFindConfigHistoryFetchRows(int pageNo, int pageSize);

/**
* Get previous config detail.
* The default sql:
Expand All @@ -83,7 +94,7 @@ default String detailPreviousConfigHistory() {
return "SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,gmt_modified "
+ "FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?)";
}

/**
* 获取返回表名.
*
Expand Down

0 comments on commit 65da789

Please sign in to comment.