Skip to content

Conversation

@LanceAdd
Copy link
Member

@LanceAdd LanceAdd commented Jan 19, 2026

变更说明

本 PR 主要对代码库进行了重构,以提升类型安全性和优化连接管理实现。

详细变更

1. 数据库连接管理优化

  • 修改 RegisterNilChecker方法返回实例以支持链式调用,涉及 KVMapListKVMapTSetAVLKVTreeBKVTreeRedBlackKVTree 等多个容器类型
  • 更新 Core结构体中 links字段类型为类型安全的 KVMap[ConfigNode, *sql.DB]
  • 添加专门的链接检查器函数用于连接池管理
  • 使用泛型 KVMap替代原始 map 类型提升类型安全性
  • 简化连接关闭逻辑并移除不必要的类型断言
  • 优化统计功能中的迭代器实现提高性能

2. 数据库驱动类型安全增强

  • 将 dm、gaussdb、mssql、oracle 驱动中的 conflictKeySetgset.New修改为 gset.NewStrSet
  • 统一使用字符串集合类型以提高类型安全性

3. 配置文件适配器类型安全改进

  • jsonMapStrAnyMap 类型更改为泛型 KVMap[string, *gjson.Json] 类型
  • 添加 jsonMapChecker 函数用于 JSON 对象验证
  • 使用 NewKVMapWithChecker 替代 NewStrAnyMap 提高类型安全性
  • 简化数据库链接关闭日志中的键值转换逻辑

影响范围

  • 数据库连接管理模块
  • 多个数据库驱动实现
  • 配置文件管理系统

- 修改 RegisterNilChecker 方法返回实例以支持链式调用
- 更新 Core 结构体中 links 字段类型为类型安全的 KVMap
- 添加专门的链接检查器函数用于连接池管理
- 使用泛型 KVMap 替代原始 map 类型提升类型安全性
- 简化连接关闭逻辑并移除不必要的类型断言
- 优化统计功能中的迭代器实现提高性能
- 将 jsonMap 从 StrAnyMap 类型更改为泛型 KVMap[string, *gjson.Json] 类型
- 添加 jsonMapChecker 函数用于 JSON 对象验证
- 使用 NewKVMapWithChecker 替代 NewStrAnyMap 提高类型安全性
- 修改 GetOrSetFuncLock 回调函数返回类型为 *gjson.Json
- 简化数据库链接关闭日志中的键值转换逻辑
- 将 dm 驱动中的 conflictKeySet 从 gset.New 修改为 gset.NewStrSet
- 将 gaussdb 驱动中的 conflictKeySet 从 gset.New 修改为 gset.NewStrSet
- 将 mssql 驱动中的 conflictKeySet 从 gset.New 修改为 gset.NewStrSet
- 将 oracle 驱动中的 conflictKeySet 从 gset.New 修改为 gset.NewStrSet
- 统一使用字符串集合类型以提高类型安全性
@gqcn gqcn added the awesome It's awesome! We keep watching. label Jan 21, 2026
@gqcn gqcn requested a review from Copilot January 21, 2026 11:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the codebase to improve type safety by migrating from untyped containers (gmap.Map, gset.New) to type-safe generic containers (gmap.KVMap[K, V], gset.NewStrSet).

Changes:

  • Migrated database connection pool management to use type-safe KVMap[ConfigNode, *sql.DB] instead of raw map[any]any
  • Updated database drivers (dm, gaussdb, mssql, oracle) to use gset.NewStrSet for string-only conflict key sets
  • Enhanced configuration file adapter to use typed KVMap[string, *gjson.Json] for JSON object storage
  • Modified RegisterNilChecker methods across container types to return receiver instances for method chaining support

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
database/gdb/gdb.go Updated Core struct to use typed KVMap for database links and added linksChecker function
database/gdb/gdb_core.go Simplified connection closing logic with typed map callback
database/gdb/gdb_core_stats.go Updated iterator to use typed callback parameters
contrib/drivers/dm/dm_do_insert.go Changed conflictKeySet from generic gset.New to gset.NewStrSet
contrib/drivers/gaussdb/gaussdb_do_insert.go Changed conflictKeySet from generic gset.New to gset.NewStrSet
contrib/drivers/mssql/mssql_do_insert.go Changed conflictKeySet from generic gset.New to gset.NewStrSet
contrib/drivers/oracle/oracle_do_insert.go Changed conflictKeySet from generic gset.New to gset.NewStrSet
os/gcfg/gcfg_adapter_file.go Migrated jsonMap to typed KVMap with custom nil checker
container/gmap/gmap_hash_k_v_map.go Modified RegisterNilChecker to return receiver for method chaining
container/gmap/gmap_list_k_v_map.go Modified RegisterNilChecker to return receiver for method chaining
container/gset/gset_t_set.go Modified RegisterNilChecker to return receiver for method chaining
container/gtree/gtree_k_v_avltree.go Modified RegisterNilChecker to return receiver for method chaining
container/gtree/gtree_k_v_btree.go Modified RegisterNilChecker to return receiver for method chaining
container/gtree/gtree_k_v_redblacktree.go Modified RegisterNilChecker to return receiver for method chaining

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gqcn gqcn added the wip label Jan 22, 2026
@gqcn
Copy link
Member

gqcn commented Jan 22, 2026

这个PR先hang一段时间,感觉这个泛型版本的NilChecker机制有些繁琐,我看看能否改进。

@LanceAdd
Copy link
Member Author

这个PR先hang一段时间,感觉这个泛型版本的NilChecker机制有些繁琐,我看看能否改进。

emmm其实之前已经改过一批合进去了

@gqcn gqcn changed the title feat(instance):migrate instance containers to type-safe generics refactor(container): add default nil checker, rename RegisterNilChecker to SetNilChecker, migrate instance containers to type-safe generics Jan 23, 2026
@gqcn gqcn merged commit 7321170 into gogf:master Jan 23, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awesome It's awesome! We keep watching. wip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants