Commit 4f5dbb2288912f74500cdc902382a5d28d040d78
1 parent
b8c728ae
feat: 优化代码生成列表加载速度
Showing
1 changed file
with
20 additions
and
31 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java
| ... | ... | @@ -12,12 +12,9 @@ import com.baomidou.mybatisplus.generator.config.po.TableInfo; |
| 12 | 12 | import com.baomidou.mybatisplus.generator.config.rules.DateType; |
| 13 | 13 | import org.springframework.stereotype.Service; |
| 14 | 14 | |
| 15 | -import javax.annotation.PostConstruct; | |
| 16 | 15 | import javax.annotation.Resource; |
| 17 | 16 | import java.util.Comparator; |
| 18 | -import java.util.HashMap; | |
| 19 | 17 | import java.util.List; |
| 20 | -import java.util.Map; | |
| 21 | 18 | import java.util.stream.Collectors; |
| 22 | 19 | |
| 23 | 20 | /** |
| ... | ... | @@ -31,26 +28,6 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { |
| 31 | 28 | @Resource |
| 32 | 29 | private DataSourceConfigService dataSourceConfigService; |
| 33 | 30 | |
| 34 | - private final Map<Long, ConfigBuilder> ConfigBuilderMap = new HashMap<>(); | |
| 35 | - | |
| 36 | - @PostConstruct | |
| 37 | - public void initConfigBuilderMap() { | |
| 38 | - for (DataSourceConfigDO config : dataSourceConfigService.getDataSourceConfigList()) { | |
| 39 | - // 使用 MyBatis Plus Generator 解析表结构 | |
| 40 | - DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(config.getUrl(), config.getUsername(), | |
| 41 | - config.getPassword()).build(); | |
| 42 | - StrategyConfig.Builder strategyConfig = new StrategyConfig.Builder(); | |
| 43 | - // 移除工作流和定时任务前缀的表名 // TODO 未来做成可配置 | |
| 44 | - strategyConfig.addExclude("ACT_[\\S\\s]+|QRTZ_[\\S\\s]+|FLW_[\\S\\s]+"); | |
| 45 | - | |
| 46 | - GlobalConfig globalConfig = new GlobalConfig.Builder().dateType(DateType.TIME_PACK).build(); // 只使用 Date 类型,不使用 LocalDate | |
| 47 | - ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, strategyConfig.build(), | |
| 48 | - null, globalConfig, null); | |
| 49 | - | |
| 50 | - ConfigBuilderMap.put(config.getId(), builder); | |
| 51 | - } | |
| 52 | - } | |
| 53 | - | |
| 54 | 31 | @Override |
| 55 | 32 | public List<TableInfo> getTableList(Long dataSourceConfigId, String nameLike, String commentLike) { |
| 56 | 33 | List<TableInfo> tables = getTableList0(dataSourceConfigId, null); |
| ... | ... | @@ -65,16 +42,28 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { |
| 65 | 42 | } |
| 66 | 43 | |
| 67 | 44 | public List<TableInfo> getTableList0(Long dataSourceConfigId, String name) { |
| 68 | - ConfigBuilder builder = ConfigBuilderMap.get(dataSourceConfigId); | |
| 69 | - Assert.notNull(builder, "数据源({}) 不存在!", dataSourceConfigId); | |
| 45 | + // 获得数据源配置 | |
| 46 | + DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(dataSourceConfigId); | |
| 47 | + Assert.notNull(config, "数据源({}) 不存在!", dataSourceConfigId); | |
| 70 | 48 | |
| 49 | + // 使用 MyBatis Plus Generator 解析表结构 | |
| 50 | + DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(config.getUrl(), config.getUsername(), | |
| 51 | + config.getPassword()).build(); | |
| 52 | + StrategyConfig.Builder strategyConfig = new StrategyConfig.Builder(); | |
| 53 | + if (StrUtil.isNotEmpty(name)) { | |
| 54 | + strategyConfig.addInclude(name); | |
| 55 | + }else{ | |
| 56 | + // 移除工作流和定时任务前缀的表名 // TODO 未来做成可配置 | |
| 57 | + strategyConfig.addExclude("ACT_[\\S\\s]+|QRTZ_[\\S\\s]+|FLW_[\\S\\s]+"); | |
| 58 | + } | |
| 59 | + | |
| 60 | + GlobalConfig globalConfig = new GlobalConfig.Builder().dateType(DateType.TIME_PACK).build(); // 只使用 Date 类型,不使用 LocalDate | |
| 61 | + ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, strategyConfig.build(), | |
| 62 | + null, globalConfig, null); | |
| 71 | 63 | // 按照名字排序 |
| 72 | 64 | List<TableInfo> tables = builder.getTableInfoList(); |
| 73 | - if (StrUtil.isBlank(name)) { | |
| 74 | - tables.sort(Comparator.comparing(TableInfo::getName)); | |
| 75 | - return tables; | |
| 76 | - } else { | |
| 77 | - return CollUtil.filter(tables, tableInfo -> tableInfo.getName().equals(name)); | |
| 78 | - } | |
| 65 | + tables.sort(Comparator.comparing(TableInfo::getName)); | |
| 66 | + return tables; | |
| 79 | 67 | } |
| 68 | + | |
| 80 | 69 | } | ... | ... |