Commit b8c728aef8a8f94938d49c4a5ff90e8632ec1e37
1 parent
161205d3
feat: 优化代码生成列表加载速度
Showing
2 changed files
with
31 additions
and
20 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java
| ... | ... | @@ -237,10 +237,6 @@ public class CodegenServiceImpl implements CodegenService { |
| 237 | 237 | @Override |
| 238 | 238 | public List<DatabaseTableRespVO> getDatabaseTableList(Long dataSourceConfigId, String name, String comment) { |
| 239 | 239 | List<TableInfo> tables = databaseTableService.getTableList(dataSourceConfigId, name, comment); |
| 240 | - // 移除置顶前缀的表名 // TODO 未来做成可配置 | |
| 241 | - tables.removeIf(table -> table.getName().toUpperCase().startsWith("QRTZ_")); | |
| 242 | - tables.removeIf(table -> table.getName().toUpperCase().startsWith("ACT_")); | |
| 243 | - tables.removeIf(table -> table.getName().toUpperCase().startsWith("FLW_")); | |
| 244 | 240 | // 移除已经生成的表 |
| 245 | 241 | // 移除在 Codegen 中,已经存在的 |
| 246 | 242 | Set<String> existsTables = CollectionUtils.convertSet( | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java
| ... | ... | @@ -12,9 +12,12 @@ 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; | |
| 15 | 16 | import javax.annotation.Resource; |
| 16 | 17 | import java.util.Comparator; |
| 18 | +import java.util.HashMap; | |
| 17 | 19 | import java.util.List; |
| 20 | +import java.util.Map; | |
| 18 | 21 | import java.util.stream.Collectors; |
| 19 | 22 | |
| 20 | 23 | /** |
| ... | ... | @@ -28,6 +31,26 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { |
| 28 | 31 | @Resource |
| 29 | 32 | private DataSourceConfigService dataSourceConfigService; |
| 30 | 33 | |
| 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 | + | |
| 31 | 54 | @Override |
| 32 | 55 | public List<TableInfo> getTableList(Long dataSourceConfigId, String nameLike, String commentLike) { |
| 33 | 56 | List<TableInfo> tables = getTableList0(dataSourceConfigId, null); |
| ... | ... | @@ -42,24 +65,16 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { |
| 42 | 65 | } |
| 43 | 66 | |
| 44 | 67 | public List<TableInfo> getTableList0(Long dataSourceConfigId, String name) { |
| 45 | - // 获得数据源配置 | |
| 46 | - DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(dataSourceConfigId); | |
| 47 | - Assert.notNull(config, "数据源({}) 不存在!", dataSourceConfigId); | |
| 68 | + ConfigBuilder builder = ConfigBuilderMap.get(dataSourceConfigId); | |
| 69 | + Assert.notNull(builder, "数据源({}) 不存在!", dataSourceConfigId); | |
| 48 | 70 | |
| 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 | - } | |
| 56 | - GlobalConfig globalConfig = new GlobalConfig.Builder().dateType(DateType.TIME_PACK).build(); // 只使用 Date 类型,不使用 LocalDate | |
| 57 | - ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, strategyConfig.build(), | |
| 58 | - null, globalConfig, null); | |
| 59 | 71 | // 按照名字排序 |
| 60 | 72 | List<TableInfo> tables = builder.getTableInfoList(); |
| 61 | - tables.sort(Comparator.comparing(TableInfo::getName)); | |
| 62 | - return tables; | |
| 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 | + } | |
| 63 | 79 | } |
| 64 | - | |
| 65 | 80 | } | ... | ... |