forked from github/dataease
Merge pull request #12185 from dataease/pr@dev-v2@refactor_ds
refactor: 数据集预览界面数据加载速度 #12099
This commit is contained in:
commit
b3a432761f
@ -250,8 +250,6 @@ public class DatasetDataManage {
|
||||
map.put("allFields", fieldList);
|
||||
}
|
||||
map.put("sql", Base64.getEncoder().encodeToString(querySQL.getBytes()));
|
||||
String replaceSql = provider.rebuildSQL(SQLProvider.createQuerySQL(sqlMeta, false, false, false), sqlMeta, crossDs, dsMap);
|
||||
map.put("total", getDatasetTotal(datasetGroupInfoDTO, replaceSql, null));
|
||||
return map;
|
||||
}
|
||||
|
||||
@ -263,6 +261,56 @@ public class DatasetDataManage {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public Long getDatasetCountWithWhere(Long datasetGroupId) throws Exception {
|
||||
DatasetGroupInfoDTO datasetGroupInfoDTO = datasetGroupManage.getForCount(datasetGroupId);
|
||||
Map<String, Object> sqlMap = datasetSQLManage.getUnionSQLForEdit(datasetGroupInfoDTO, null);
|
||||
String sql = (String) sqlMap.get("sql");
|
||||
|
||||
// 获取allFields
|
||||
List<DatasetTableFieldDTO> fields = datasetGroupInfoDTO.getAllFields();
|
||||
if (ObjectUtils.isEmpty(fields)) {
|
||||
DEException.throwException(Translator.get("i18n_no_fields"));
|
||||
}
|
||||
|
||||
buildFieldName(sqlMap, fields);
|
||||
|
||||
Map<Long, DatasourceSchemaDTO> dsMap = (Map<Long, DatasourceSchemaDTO>) sqlMap.get("dsMap");
|
||||
DatasourceUtils.checkDsStatus(dsMap);
|
||||
List<String> dsList = new ArrayList<>();
|
||||
for (Map.Entry<Long, DatasourceSchemaDTO> next : dsMap.entrySet()) {
|
||||
dsList.add(next.getValue().getType());
|
||||
}
|
||||
boolean crossDs = Utils.isCrossDs(dsMap);
|
||||
if (!crossDs) {
|
||||
if (notFullDs.contains(dsMap.entrySet().iterator().next().getValue().getType()) && (boolean) sqlMap.get("isFullJoin")) {
|
||||
DEException.throwException(Translator.get("i18n_not_full"));
|
||||
}
|
||||
sql = Utils.replaceSchemaAlias(sql, dsMap);
|
||||
}
|
||||
|
||||
List<DataSetRowPermissionsTreeDTO> rowPermissionsTree = new ArrayList<>();
|
||||
TokenUserBO user = AuthUtils.getUser();
|
||||
if (user != null) {
|
||||
rowPermissionsTree = permissionManage.getRowPermissionsTree(datasetGroupInfoDTO.getId(), user.getUserId());
|
||||
}
|
||||
|
||||
Provider provider;
|
||||
if (crossDs) {
|
||||
provider = ProviderFactory.getDefaultProvider();
|
||||
} else {
|
||||
provider = ProviderFactory.getProvider(dsList.getFirst());
|
||||
}
|
||||
|
||||
// build query sql
|
||||
SQLMeta sqlMeta = new SQLMeta();
|
||||
Table2SQLObj.table2sqlobj(sqlMeta, null, "(" + sql + ")", crossDs);
|
||||
Field2SQLObj.field2sqlObj(sqlMeta, fields, fields, crossDs, dsMap, Utils.getParams(fields), null, pluginManage);
|
||||
WhereTree2Str.transFilterTrees(sqlMeta, rowPermissionsTree, fields, crossDs, dsMap, Utils.getParams(fields), null, pluginManage);
|
||||
Order2SQLObj.getOrders(sqlMeta, datasetGroupInfoDTO.getSortFields(), fields, crossDs, dsMap, Utils.getParams(fields), null, pluginManage);
|
||||
String replaceSql = provider.rebuildSQL(SQLProvider.createQuerySQL(sqlMeta, false, false, false), sqlMeta, crossDs, dsMap);
|
||||
return getDatasetTotal(datasetGroupInfoDTO, replaceSql, null);
|
||||
}
|
||||
|
||||
public Long getDatasetTotal(DatasetGroupInfoDTO datasetGroupInfoDTO, String s, ChartExtRequest request) throws Exception {
|
||||
Map<String, Object> sqlMap = datasetSQLManage.getUnionSQLForEdit(datasetGroupInfoDTO, request);
|
||||
Map<Long, DatasourceSchemaDTO> dsMap = (Map<Long, DatasourceSchemaDTO>) sqlMap.get("dsMap");
|
||||
|
@ -73,6 +73,11 @@ public class DatasetDataServer implements DatasetDataApi {
|
||||
return datasetDataManage.getDatasetTotal(datasetGroupInfoDTO.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDatasetTotal(DatasetGroupInfoDTO datasetGroupInfoDTO) throws Exception {
|
||||
return datasetDataManage.getDatasetCountWithWhere(datasetGroupInfoDTO.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BaseTreeNodeDTO> getFieldValueTree(MultFieldValuesRequest multFieldValuesRequest) throws Exception {
|
||||
try {
|
||||
|
@ -172,6 +172,12 @@ export const getDatasetPreview = async (id): Promise<FieldData> => {
|
||||
})
|
||||
}
|
||||
|
||||
export const getDatasetTotal = async (id): Promise<FieldData> => {
|
||||
return request.post({ url: `/datasetData/getDatasetTotal`, data: { id: id } }).then(res => {
|
||||
return res?.data
|
||||
})
|
||||
}
|
||||
|
||||
export const getDatasetDetails = async (id): Promise<Dataset> => {
|
||||
return request.post({ url: `/datasetTree/details/${id}`, data: {} }).then(res => {
|
||||
return res?.data
|
||||
|
@ -38,7 +38,8 @@ import {
|
||||
barInfoApi,
|
||||
perDelete,
|
||||
exportDatasetData,
|
||||
exportLimit
|
||||
exportLimit,
|
||||
getDatasetTotal
|
||||
} from '@/api/dataset'
|
||||
import EmptyBackground from '@/components/empty-background/src/EmptyBackground.vue'
|
||||
import DeResourceGroupOpt from '@/views/common/DeResourceGroupOpt.vue'
|
||||
@ -313,7 +314,7 @@ onBeforeMount(() => {
|
||||
|
||||
const columns = shallowRef([])
|
||||
const tableData = shallowRef([])
|
||||
const total = ref(0)
|
||||
const total = ref(null)
|
||||
|
||||
const handleNodeClick = (data: BusiTreeNode) => {
|
||||
if (!data.leaf) {
|
||||
@ -459,11 +460,13 @@ const handleClick = (tabName: TabPaneName) => {
|
||||
dataPreview = (res?.data?.data as Array<{}>) || []
|
||||
columns.value = columnsPreview
|
||||
tableData.value = dataPreview
|
||||
total.value = res.total
|
||||
})
|
||||
.finally(() => {
|
||||
dataPreviewLoading.value = false
|
||||
})
|
||||
getDatasetTotal(nodeInfo.id).then(res => {
|
||||
total.value = res
|
||||
})
|
||||
break
|
||||
case 'structPreview':
|
||||
columns.value = allFieldsColumns
|
||||
|
@ -50,6 +50,10 @@ public interface DatasetDataApi {
|
||||
@PostMapping("getDatasetCount")
|
||||
Long getDatasetCount(@RequestBody DatasetGroupInfoDTO datasetGroupInfoDTO) throws Exception;
|
||||
|
||||
@Operation(summary = "获取数据集数据量", hidden = true)
|
||||
@PostMapping("getDatasetTotal")
|
||||
Long getDatasetTotal(@RequestBody DatasetGroupInfoDTO datasetGroupInfoDTO) throws Exception;
|
||||
|
||||
@Operation(summary = "获取下拉树数据", hidden = true)
|
||||
@PostMapping("getFieldTree")
|
||||
List<BaseTreeNodeDTO> getFieldValueTree(@RequestBody MultFieldValuesRequest multFieldValuesRequest) throws Exception;
|
||||
|
Loading…
Reference in New Issue
Block a user