Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(database/gdb): Optimize SoftTime feature#4559

Merged
gqcn merged 4 commits intogogf:masterfrom
LanceAdd:fix/SoftTime
Dec 12, 2025
Merged

feat(database/gdb): Optimize SoftTime feature#4559
gqcn merged 4 commits intogogf:masterfrom
LanceAdd:fix/SoftTime

Conversation

@LanceAdd
Copy link
Member

@LanceAdd LanceAdd commented Dec 11, 2025

本次PR主要针对GoFrame ORM中的软删除SoftTime功能进行了优化

  • 新增SoftTimeFieldType枚举类型,用于区分创建、更新、删除三种不同的软时间字段
  • 替代之前使用的魔数方式,提高类型安全性
  • 将原有的6个方法精简为4个方法, 合并了三个几乎相同的GetFieldNameAndTypeFor*方法为统一的方法

This pull request refactors and simplifies the "soft time" (created/updated/deleted timestamp) handling logic in the database layer, making the codebase more maintainable and extensible. The changes consolidate multiple similar methods into general-purpose ones, improve cache key generation, and clarify the logic for generating and applying soft time field values and conditions.

Key changes include:

Soft Time API Refactoring and Simplification

  • Consolidated multiple methods (GetFieldNameAndTypeForCreate, GetFieldNameAndTypeForUpdate, GetFieldNameAndTypeForDelete) into a single, parameterized method GetFieldInfo, reducing code duplication and making it easier to support new soft time field types. The interface and implementation for soft time maintenance (iSoftTimeMaintainer, softTimeMaintainer) have been updated accordingly. [1] [2]
  • Combined and renamed methods for generating soft time field values and delete conditions, such as merging GetValueByFieldTypeForCreateOrUpdate into GetFieldValue, and GetWhereConditionForDelete into GetDeleteCondition. Related usages throughout the codebase have been updated to use the new methods. [1] [2] [3] [4] [5] [6]

Soft Delete Logic Improvements

  • Refactored the logic for building soft delete WHERE conditions and generating update data, with clearer and more robust handling of field types and prefixes. Introduced helper methods like buildDeleteCondition, GetDeleteData, and improved error logging for invalid field types. [1] [2]

Cache Key Generation Enhancements

  • Added dedicated helper functions for generating cache keys for table names, table fields, select queries, and soft time field/type lookups, improving cache consistency and code readability. [1] [2] [3] [4]

General Code Cleanup

  • Removed redundant code, clarified comments, and improved naming throughout the affected files, making the code easier to follow and maintain. [1] [2]

Let me know if you'd like a walkthrough of any specific part of the refactored soft time logic!

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 optimizes the soft delete SoftTime feature in the GoFrame ORM by introducing type safety and reducing code duplication. The changes introduce a new SoftTimeFieldType enum to distinguish between create, update, and delete field purposes, replacing the previous magic number approach.

Key Changes:

  • Introduced SoftTimeFieldType enum with three constants: SoftTimeFieldCreate, SoftTimeFieldUpdate, SoftTimeFieldDelete
  • Consolidated three nearly identical GetFieldNameAndTypeFor* methods into a single unified GetFieldInfo method
  • Renamed and refactored interface methods for better clarity (e.g., GetWhereConditionForDeleteGetDeleteCondition, GetDataByFieldNameAndTypeForDeleteGetDeleteData)
  • Extracted and simplified helper methods (getEmptyValue, getAutoValue, getTimestampValue) to improve code organization

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
database/gdb/gdb_model_soft_time.go Core refactoring: adds SoftTimeFieldType enum, consolidates methods, refactors helper functions, and improves code organization
database/gdb/gdb_model_update.go Updates method calls to use new GetFieldInfo and GetFieldValue methods
database/gdb/gdb_model_insert.go Updates method calls to use new GetFieldInfo and GetFieldValue methods
database/gdb/gdb_model_delete.go Updates method calls to use new GetFieldInfo and GetDeleteData methods
database/gdb/gdb_model_select.go Updates method call to use new GetDeleteCondition method
database/gdb/gdb_func.go Adds utility functions for cache key generation: genTableNamesCacheKey and genSoftTimeFieldNameTypeCacheKey
database/gdb/gdb_core.go Refactors to use new genTableNamesCacheKey utility function

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

@gqcn
Copy link
Member

gqcn commented Dec 11, 2025

@LanceAdd 我对整体改动没什么疑问,注意修正下copilot提出的comment就好。我近期也会改动这里,希望尽快修正提交。

@LanceAdd
Copy link
Member Author

@LanceAdd 我对整体改动没什么疑问,注意修正下copilot提出的comment就好。我近期也会改动这里,希望尽快修正提交。

改完了

@gqcn gqcn merged commit b59824e into gogf:master Dec 12, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants