From bb01077806ce28ebb6bd414cd71f9cc2a253a4c9 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Sun, 1 Dec 2024 14:44:36 +0800 Subject: [PATCH] =?UTF-8?q?perf(X-Pack):=20=E6=95=B0=E6=8D=AE=E6=BA=90?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=95=B0=E9=87=8F=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataset/manage/DatasetDataManage.java | 10 +++++-- .../dataset/manage/DatasetSQLManage.java | 10 +++++-- .../datasource/manage/DataSourceManage.java | 11 ++++++-- .../datasource/server/DatasourceServer.java | 28 +++++++++---------- de-xpack | 2 +- 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetDataManage.java b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetDataManage.java index b4d59189e7..f074fcb534 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetDataManage.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetDataManage.java @@ -16,6 +16,7 @@ import io.dataease.dataset.utils.FieldUtils; import io.dataease.dataset.utils.TableUtils; import io.dataease.datasource.dao.auto.entity.CoreDatasource; import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper; +import io.dataease.datasource.manage.DataSourceManage; import io.dataease.datasource.manage.EngineManage; import io.dataease.datasource.utils.DatasourceUtils; import io.dataease.engine.constant.ExtFieldConstant; @@ -80,6 +81,9 @@ public class DatasetDataManage { @Resource private CorePermissionManage corePermissionManage; + @Resource + private DataSourceManage dataSourceManage; + private static Logger logger = LoggerFactory.getLogger(DatasetDataManage.class); public static final List notFullDs = List.of("mysql", "mariadb", "Excel", "API"); @@ -90,7 +94,7 @@ public class DatasetDataManage { String type = datasetTableDTO.getType(); DatasetTableInfoDTO tableInfoDTO = JsonUtil.parseObject(datasetTableDTO.getInfo(), DatasetTableInfoDTO.class); if (StringUtils.equalsIgnoreCase(type, DatasetTableType.DB) || StringUtils.equalsIgnoreCase(type, DatasetTableType.SQL)) { - CoreDatasource coreDatasource = coreDatasourceMapper.selectById(datasetTableDTO.getDatasourceId()); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(datasetTableDTO.getDatasourceId()); DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO(); if (StringUtils.equalsIgnoreCase("excel", coreDatasource.getType()) || StringUtils.equalsIgnoreCase("api", coreDatasource.getType())) { coreDatasource = engineManage.getDeEngine(); @@ -133,7 +137,7 @@ public class DatasetDataManage { tableFields = provider.fetchTableField(datasourceRequest); } else if (StringUtils.equalsIgnoreCase(type, DatasetTableType.Es)) { - CoreDatasource coreDatasource = coreDatasourceMapper.selectById(datasetTableDTO.getDatasourceId()); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(datasetTableDTO.getDatasourceId()); Provider provider = ProviderFactory.getProvider(type); DatasourceRequest datasourceRequest = new DatasourceRequest(); DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO(); @@ -381,7 +385,7 @@ public class DatasetDataManage { } public Map previewSql(PreviewSqlDTO dto) throws DEException { - CoreDatasource coreDatasource = coreDatasourceMapper.selectById(dto.getDatasourceId()); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(dto.getDatasourceId()); DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO(); if (coreDatasource.getType().equalsIgnoreCase("API") || coreDatasource.getType().equalsIgnoreCase("Excel")) { BeanUtils.copyBean(datasourceSchemaDTO, engineManage.getDeEngine()); diff --git a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java index ed7cce3aaf..27bec793ee 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java @@ -10,6 +10,7 @@ import io.dataease.dataset.utils.SqlUtils; import io.dataease.dataset.utils.TableUtils; import io.dataease.datasource.dao.auto.entity.CoreDatasource; import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper; +import io.dataease.datasource.manage.DataSourceManage; import io.dataease.datasource.manage.EngineManage; import io.dataease.engine.constant.ExtFieldConstant; import io.dataease.engine.constant.SQLConstants; @@ -62,6 +63,9 @@ public class DatasetSQLManage { @Autowired(required = false) private PluginManageApi pluginManage; + @Resource + private DataSourceManage dataSourceManage; + private static Logger logger = LoggerFactory.getLogger(DatasetSQLManage.class); private List filterParameters(ChartExtRequest chartExtRequest, Long datasetTableId) { @@ -379,7 +383,7 @@ public class DatasetSQLManage { DatasourceSchemaDTO datasourceSchemaDTO = dsMap.get(datasourceId); String type; if (datasourceSchemaDTO == null) { - CoreDatasource coreDatasource = coreDatasourceMapper.selectById(datasourceId); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(datasourceId); if (coreDatasource == null) { DEException.throwException(Translator.get("i18n_dataset_ds_error") + ",ID:" + datasourceId); } @@ -479,7 +483,7 @@ public class DatasetSQLManage { String schemaAlias; if (StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.DB) || StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.SQL)) { - CoreDatasource coreDatasource = coreDatasourceMapper.selectById(ds.getDatasourceId()); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(ds.getDatasourceId()); if (coreDatasource == null) { DEException.throwException(Translator.get("i18n_dataset_ds_error") + ",ID:" + ds.getDatasourceId()); } @@ -501,7 +505,7 @@ public class DatasetSQLManage { dsMap.put(coreDatasource.getId(), datasourceSchemaDTO); } } else if (StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.Es)) { - CoreDatasource coreDatasource = coreDatasourceMapper.selectById(ds.getDatasourceId()); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(ds.getDatasourceId()); schemaAlias = String.format(SQLConstants.SCHEMA, coreDatasource.getId()); if (!dsMap.containsKey(coreDatasource.getId())) { DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO(); diff --git a/core/core-backend/src/main/java/io/dataease/datasource/manage/DataSourceManage.java b/core/core-backend/src/main/java/io/dataease/datasource/manage/DataSourceManage.java index 0a79c72d9b..8e3540bec6 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/manage/DataSourceManage.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/manage/DataSourceManage.java @@ -140,7 +140,7 @@ public class DataSourceManage { public void move(DatasourceDTO dataSourceDTO) { Long id = dataSourceDTO.getId(); CoreDatasource sourceData = null; - if (ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(sourceData = coreDatasourceMapper.selectById(id))) { + if (ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(sourceData = getCoreDatasource(id))) { DEException.throwException("resource not exist"); } checkName(dataSourceDTO); @@ -157,14 +157,19 @@ public class DataSourceManage { } - public void encryptDsConfig(){ + public void encryptDsConfig() { coreDatasourceMapper.selectList(null).forEach(dataSource -> { coreDatasourceMapper.updateById(dataSource); }); } + @XpackInteract(value = "datasourceResourceTree", before = false) + public CoreDatasource getCoreDatasource(Long id) { + return coreDatasourceMapper.selectById(id); + } + public DatasourceDTO getDs(Long id) { - CoreDatasource coreDatasource = coreDatasourceMapper.selectById(id); + CoreDatasource coreDatasource = getCoreDatasource(id); DatasourceDTO dto = new DatasourceDTO(); BeanUtils.copyBean(dto, coreDatasource); return dto; diff --git a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java index 5370af6d50..a22481598a 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java @@ -107,8 +107,6 @@ public class DatasourceServer implements DatasourceApi { private PluginManageApi pluginManage; @Autowired(required = false) private RelationApi relationManage; - @Autowired - private CoreDatasourceMapper coreDatasourceMapper; public enum UpdateType { all_scope, add_scope @@ -208,7 +206,7 @@ public class DatasourceServer implements DatasourceApi { if (StringUtils.isEmpty(dataSourceDTO.getName())) { DEException.throwException("名称不能为空!"); } - CoreDatasource datasource = datasourceMapper.selectById(dataSourceDTO.getId()); + CoreDatasource datasource = dataSourceManage.getCoreDatasource(dataSourceDTO.getId()); datasource.setName(dataSourceDTO.getName()); dataSourceDTO.setPid(datasource.getPid()); dataSourceManage.checkName(dataSourceDTO); @@ -490,7 +488,7 @@ public class DatasourceServer implements DatasourceApi { @Override public DatasourceDTO getSimpleDs(Long datasourceId) throws DEException { - CoreDatasource datasource = datasourceMapper.selectById(datasourceId); + CoreDatasource datasource = dataSourceManage.getCoreDatasource(datasourceId); if (datasource == null) { DEException.throwException("不存在的数据源!"); } @@ -517,7 +515,7 @@ public class DatasourceServer implements DatasourceApi { @Override public String getName(Long datasourceId) throws DEException { - CoreDatasource datasource = datasourceMapper.selectById(datasourceId); + CoreDatasource datasource = dataSourceManage.getCoreDatasource(datasourceId); if (datasource == null) { DEException.throwException("不存在的数据源!"); } @@ -578,7 +576,7 @@ public class DatasourceServer implements DatasourceApi { } public void recursionDel(Long datasourceId) throws DEException { - CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(datasourceId); if (ObjectUtils.isEmpty(coreDatasource)) { return; } @@ -635,7 +633,7 @@ public class DatasourceServer implements DatasourceApi { @Override public DatasourceDTO validate(Long datasourceId) throws DEException { CoreDatasource coreDatasource = new CoreDatasource(); - BeanUtils.copyBean(coreDatasource, datasourceMapper.selectById(datasourceId)); + BeanUtils.copyBean(coreDatasource, dataSourceManage.getCoreDatasource(datasourceId)); return validate(coreDatasource); } @@ -671,7 +669,7 @@ public class DatasourceServer implements DatasourceApi { @Override public List getTables(DatasetTableDTO datasetTableDTO) throws DEException { - CoreDatasource coreDatasource = datasourceMapper.selectById(datasetTableDTO.getDatasourceId()); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(datasetTableDTO.getDatasourceId()); if (coreDatasource == null) { DEException.throwException("无效数据源!"); } @@ -706,7 +704,7 @@ public class DatasourceServer implements DatasourceApi { if (!getTables(datasetTableDTO).stream().map(DatasetTableDTO::getTableName).collect(Collectors.toList()).contains(tableName)) { DEException.throwException("无效的表名!"); } - CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(Long.parseLong(datasourceId)); DatasourceRequest datasourceRequest = new DatasourceRequest(); datasourceRequest.setDatasource(transDTO(coreDatasource)); if (coreDatasource.getType().equals("API") || coreDatasource.getType().equals("Excel")) { @@ -746,7 +744,7 @@ public class DatasourceServer implements DatasourceApi { public void syncApiDs(Map req) throws Exception { Long datasourceId = Long.valueOf(req.get("datasourceId")); CoreDatasourceTask coreDatasourceTask = datasourceTaskServer.selectByDSId(datasourceId); - CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(datasourceId); DatasourceServer.UpdateType updateType = DatasourceServer.UpdateType.valueOf(coreDatasourceTask.getUpdateType()); datasourceSyncManage.extractedData(null, coreDatasource, updateType, MANUAL.toString()); } @@ -774,7 +772,7 @@ public class DatasourceServer implements DatasourceApi { private static final Integer append = 1; public ExcelFileData excelUpload(@RequestParam("file") MultipartFile file, @RequestParam("id") long datasourceId, @RequestParam("editType") Integer editType) throws DEException { - CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(datasourceId); ExcelUtils excelUtils = new ExcelUtils(); ExcelFileData excelFileData = excelUtils.excelSaveAndParse(file); @@ -983,7 +981,7 @@ public class DatasourceServer implements DatasourceApi { wrapper.orderByDesc("start_time"); Page page = new Page<>(goPage, pageSize); IPage pager = taskLogExtMapper.pager(page, wrapper); - CoreDatasource coreDatasource = datasourceMapper.selectById(dsId); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(dsId); DatasourceRequest datasourceRequest = new DatasourceRequest(); datasourceRequest.setDatasource(transDTO(coreDatasource)); List datasetTableDTOS = ApiUtils.getTables(datasourceRequest); @@ -1083,7 +1081,7 @@ public class DatasourceServer implements DatasourceApi { } private void getParents(Long pid, List ids) { - CoreDatasource parent = datasourceMapper.selectById(pid);// 查找父级folder + CoreDatasource parent = dataSourceManage.getCoreDatasource(pid);// 查找父级folder ids.add(parent.getId()); if (parent.getPid() != null && parent.getPid() != 0) { getParents(parent.getPid(), ids); @@ -1138,7 +1136,7 @@ public class DatasourceServer implements DatasourceApi { } private DatasourceDTO getDatasourceDTOById(Long datasourceId, boolean hidePw) throws DEException { - CoreDatasource datasource = datasourceMapper.selectById(datasourceId); + CoreDatasource datasource = dataSourceManage.getCoreDatasource(datasourceId); if (datasource == null) { DEException.throwException("不存在的数据源!"); } @@ -1248,7 +1246,7 @@ public class DatasourceServer implements DatasourceApi { @Override public DsSimpleVO simple(Long id) { if (ObjectUtils.isEmpty(id)) DEException.throwException("id is null"); - CoreDatasource coreDatasource = coreDatasourceMapper.selectById(id); + CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(id); if (ObjectUtils.isEmpty(coreDatasource)) return null; DsSimpleVO vo = new DsSimpleVO(); vo.setName(coreDatasource.getName()); diff --git a/de-xpack b/de-xpack index fd5754d9d6..ef5980c7a7 160000 --- a/de-xpack +++ b/de-xpack @@ -1 +1 @@ -Subproject commit fd5754d9d6d6615f9ae49addc9bbf1ad9839e29f +Subproject commit ef5980c7a78b82eb17c9a1376ad7258806014636