-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
refactor(container): add default nil checker, rename RegisterNilChecker to SetNilChecker, migrate instance containers to type-safe generics #4630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 修改 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 - 统一使用字符串集合类型以提高类型安全性
There was a problem hiding this 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 rawmap[any]any - Updated database drivers (dm, gaussdb, mssql, oracle) to use
gset.NewStrSetfor string-only conflict key sets - Enhanced configuration file adapter to use typed
KVMap[string, *gjson.Json]for JSON object storage - Modified
RegisterNilCheckermethods 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
这个PR先hang一段时间,感觉这个泛型版本的 |
emmm其实之前已经改过一批合进去了 |
…fix/generic-container-nil-checker
…f into fix/generic-container-nil-checker
fix(container): add default nil checker, rename RegisterNilChecker to SetNilChecker
chore(container): comments update
变更说明
本 PR 主要对代码库进行了重构,以提升类型安全性和优化连接管理实现。
详细变更
1. 数据库连接管理优化
RegisterNilChecker方法返回实例以支持链式调用,涉及KVMap、ListKVMap、TSet、AVLKVTree、BKVTree、RedBlackKVTree等多个容器类型Core结构体中links字段类型为类型安全的KVMap[ConfigNode, *sql.DB]KVMap替代原始 map 类型提升类型安全性2. 数据库驱动类型安全增强
conflictKeySet从gset.New修改为gset.NewStrSet3. 配置文件适配器类型安全改进
jsonMap从StrAnyMap类型更改为泛型KVMap[string, *gjson.Json]类型jsonMapChecker函数用于 JSON 对象验证NewKVMapWithChecker替代NewStrAnyMap提高类型安全性影响范围