refactor: cleanup unused code and simplify internal packages
Some checks failed
Build Backend / build (push) Successful in 1m56s
Build Backend / build-docker (push) Has been cancelled

This commit performs a significant cleanup of the codebase by removing unused functions, methods, and entire files across various internal modules. This reduces technical debt and simplifies the project structure.

Key changes include:
- **cache**: Removed unused cache key generators and metrics snapshots.
- **dto**: Removed redundant converter functions and segment creation helpers.
- **middleware**: Deleted the unused `logger.go` middleware and simplified `ratelimit.go` and `casbin.go`.
- **model**: Removed unused ID helpers, database closing functions, and batch decryption logic.
- **pkg**: Cleaned up unused utility functions in `circuitbreaker`, `crypto`, `cursor`, `hook`, and `utils`.
- **service**: Deleted `account_cleanup_service.go` and removed unused helper functions in `log_cleanup_service.go` and `sensitive_service.go`.
- **repository**: Removed unused private loading methods in `comment_repo.go`.
This commit is contained in:
2026-05-14 02:24:30 +08:00
parent d2894066f8
commit 9a1851f023
36 changed files with 0 additions and 1449 deletions

View File

@@ -4,7 +4,6 @@ import (
"strconv"
"github.com/google/uuid"
"gorm.io/gorm"
"with_you/internal/pkg/utils"
)
@@ -37,20 +36,3 @@ func SetSnowflakeInt64ID(id *int64) error {
return nil
}
func GenerateUUID() string {
return uuid.New().String()
}
func GenerateSnowflakeString() (string, error) {
id, err := utils.GetSnowflake().GenerateID()
if err != nil {
return "", err
}
return strconv.FormatInt(id, 10), nil
}
func GenerateSnowflakeInt64() (int64, error) {
return utils.GetSnowflake().GenerateID()
}
func nop(_ *gorm.DB) error { return nil }

View File

@@ -415,9 +415,3 @@ func seedMaterialSubjects(db *gorm.DB) error {
return nil
}
// CloseDB 关闭数据库连接
func CloseDB(db *gorm.DB) {
if sqlDB, err := db.DB(); err == nil {
sqlDB.Close()
}
}

View File

@@ -303,76 +303,6 @@ func (m *Message) IsInteractionNotification() bool {
}
}
// BatchDecryptMessages 批量并行解密消息
// 用于批量查询后提高解密性能,比逐条调用 AfterFind 更高效
// workerCount 指定并行工作数,如果 <= 0 则使用默认值
func BatchDecryptMessages(messages []*Message, workerCount int) error {
if len(messages) == 0 {
return nil
}
encryptor := crypto.GetMessageEncryptor()
if encryptor == nil {
// 加密器未初始化,直接解析 JSON兼容模式
for _, m := range messages {
if m.decrypted || m.SegmentsEncrypted == "" {
m.decrypted = true
continue
}
if err := json.Unmarshal([]byte(m.SegmentsEncrypted), &m.Segments); err != nil {
return err
}
m.decrypted = true
}
return nil
}
// 小批量直接串行处理
if len(messages) <= 10 {
for _, m := range messages {
if err := m.decryptSegments(); err != nil {
return err
}
}
return nil
}
// 并行解密
// 先收集需要解密的密文
ciphertexts := make([]string, len(messages))
for i, m := range messages {
ciphertexts[i] = m.SegmentsEncrypted
}
// 批量并行解密
plaintexts := encryptor.BatchDecrypt(ciphertexts, workerCount)
// 解析结果
for i, m := range messages {
if m.decrypted {
continue
}
if m.SegmentsEncrypted == "" {
m.decrypted = true
continue
}
plaintext := plaintexts[i]
if plaintext == nil {
// 解密失败,尝试直接解析(兼容旧数据)
if err := json.Unmarshal([]byte(m.SegmentsEncrypted), &m.Segments); err != nil {
continue // 忽略单条错误
}
} else {
if err := json.Unmarshal(plaintext, &m.Segments); err != nil {
continue // 忽略单条错误
}
}
m.decrypted = true
}
return nil
}
// BatchDecryptMessagesParallel 使用 worker pool 并行解密
// 这是一个更高效的版本,适用于大量消息