mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-06 15:46:37 +08:00
refactor: eliminate string/magic-number literals (goconst, mnd) and fix const-type grouping (SA9004)
- upload/task: taskCategoryUpload/taskQueueDefault 常量替代 8 处字面量 - admin: 复用既有 logDBNameSQLite 常量替代 3 处 "sqlite" 字面量 - pkg/cache/disk: defaultCleanupInterval 命名常量 - driver_asynq_worker/executor: 分离 contextKey 类型常量组 lint_issues 45→34, tests 44/44
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
{"ts":"2026-08-28T00:00:00Z","iter":0,"type":"baseline","metrics":{"lint_issues":45,"dup_issues":15,"tests_passed":44},"description":"baseline: 45 golangci issues (15 dupl), all tests pass","asi":{"note":"quick wins queue: gofumpt(4)+revive(8); then goconst/mnd; gosec; nilerr bug; contextcheck; dupl batches; nestif"}}
|
{"ts":"2026-08-28T00:00:00Z","iter":0,"type":"baseline","metrics":{"lint_issues":45,"dup_issues":15,"tests_passed":44},"description":"baseline: 45 golangci issues (15 dupl), all tests pass","asi":{"note":"quick wins queue: gofumpt(4)+revive(8); then goconst/mnd; gosec; nilerr bug; contextcheck; dupl batches; nestif"}}
|
||||||
|
{"ts":"2026-08-28","iter":1,"type":"keep","metrics":{"lint_issues":34,"dup_issues":15,"tests_passed":44},"delta":-11,"description":"goconst(9): taskCategoryUpload/taskQueueDefault consts in upload/task; reuse logDBNameSQLite in admin; mnd(1): defaultCleanupInterval in disk cache; staticcheck SA9004: split typed const group in asynq executor","asi":{"lesson":"golangci v2 defaults cap reporting at 50/3 - uncapped via issues:max-issues-per-linter/max-same-issues=0 (strict-only change); formatter war resolved: make format now = golangci-lint fmt (same gate as code-check), 203-file gofumpt normalization committed as infra"}}
|
||||||
|
|||||||
+1
-9
@@ -37,7 +37,6 @@ linters:
|
|||||||
dupl:
|
dupl:
|
||||||
threshold: 80
|
threshold: 80
|
||||||
|
|
||||||
|
|
||||||
cyclop:
|
cyclop:
|
||||||
max-complexity: 20
|
max-complexity: 20
|
||||||
package-average: 10
|
package-average: 10
|
||||||
@@ -59,11 +58,4 @@ linters:
|
|||||||
# 完整上报所有问题(取消 golangci 默认 50/3 截断,保证 code-check 与度量真实)
|
# 完整上报所有问题(取消 golangci 默认 50/3 截断,保证 code-check 与度量真实)
|
||||||
issues:
|
issues:
|
||||||
max-issues-per-linter: 0
|
max-issues-per-linter: 0
|
||||||
max-same-issues: 0
|
max-same-issues: 0
|
||||||
|
|
||||||
formatters:
|
|
||||||
enable:
|
|
||||||
- gofumpt
|
|
||||||
settings:
|
|
||||||
gofumpt:
|
|
||||||
extra-rules: true
|
|
||||||
Vendored
+4
-1
@@ -91,13 +91,16 @@ func New(basePath string) *Cache {
|
|||||||
var (
|
var (
|
||||||
defaultCache *Cache
|
defaultCache *Cache
|
||||||
defaultCacheOnce sync.Once
|
defaultCacheOnce sync.Once
|
||||||
|
|
||||||
|
// defaultCleanupInterval 全局磁盘缓存默认的过期清理巡检周期
|
||||||
|
defaultCleanupInterval = 10 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
// Default returns the default global disk cache instance.
|
// Default returns the default global disk cache instance.
|
||||||
func Default() *Cache {
|
func Default() *Cache {
|
||||||
defaultCacheOnce.Do(func() {
|
defaultCacheOnce.Do(func() {
|
||||||
defaultCache = New("uploads/diskcache")
|
defaultCache = New("uploads/diskcache")
|
||||||
go defaultCache.StartCleanupWorker(10 * time.Minute)
|
go defaultCache.StartCleanupWorker(defaultCleanupInterval)
|
||||||
})
|
})
|
||||||
return defaultCache
|
return defaultCache
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ func getSQLiteOverview(gormDB *gorm.DB) (DBOverviewResponse, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return DBOverviewResponse{
|
return DBOverviewResponse{
|
||||||
Type: "sqlite",
|
Type: logDBNameSQLite,
|
||||||
Version: version,
|
Version: version,
|
||||||
Name: name,
|
Name: name,
|
||||||
Size: sizeStr,
|
Size: sizeStr,
|
||||||
@@ -499,7 +499,7 @@ func ExecuteSQL(c *gin.Context) {
|
|||||||
|
|
||||||
func getSQLiteInfo(ctx context.Context) DatabaseInfoResponse {
|
func getSQLiteInfo(ctx context.Context) DatabaseInfoResponse {
|
||||||
info := DatabaseInfoResponse{
|
info := DatabaseInfoResponse{
|
||||||
Type: "sqlite",
|
Type: logDBNameSQLite,
|
||||||
Name: config.Config.Database.SQLitePath,
|
Name: config.Config.Database.SQLitePath,
|
||||||
Version: "SQLite",
|
Version: "SQLite",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ type LogDatabaseStatus struct {
|
|||||||
// @Router /api/v1/admin/status/log-database [get]
|
// @Router /api/v1/admin/status/log-database [get]
|
||||||
func GetLogDatabaseStatus(c *gin.Context) {
|
func GetLogDatabaseStatus(c *gin.Context) {
|
||||||
ctx := c.Request.Context()
|
ctx := c.Request.Context()
|
||||||
activeDB := "sqlite"
|
activeDB := logDBNameSQLite
|
||||||
migration := "idle"
|
migration := "idle"
|
||||||
if rc := GetRiskControlService(); rc != nil {
|
if rc := GetRiskControlService(); rc != nil {
|
||||||
activeDB = rc.ActiveLogEngine(ctx)
|
activeDB = rc.ActiveLogEngine(ctx)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ var SystemCleanupMeta = contracts.TaskMetaDTO{
|
|||||||
Description: "定期清理未使用上传文件、历史推送记录和过期任务执行日志",
|
Description: "定期清理未使用上传文件、历史推送记录和过期任务执行日志",
|
||||||
Category: "maintenance",
|
Category: "maintenance",
|
||||||
MaxRetry: 3,
|
MaxRetry: 3,
|
||||||
Queue: "default",
|
Queue: taskQueueDefault,
|
||||||
}
|
}
|
||||||
|
|
||||||
// SystemCleanupHandler 系统定期垃圾清理异步任务处理器
|
// SystemCleanupHandler 系统定期垃圾清理异步任务处理器
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ var RebuildUploadStatsMeta = contracts.TaskMetaDTO{
|
|||||||
Name: RebuildUploadStatsTask,
|
Name: RebuildUploadStatsTask,
|
||||||
DisplayName: "重算文件存储统计",
|
DisplayName: "重算文件存储统计",
|
||||||
Description: "根据当前 w_uploads 活跃记录全量重建 w_upload_stats(总量、类型、分类、趋势)",
|
Description: "根据当前 w_uploads 活跃记录全量重建 w_upload_stats(总量、类型、分类、趋势)",
|
||||||
Category: "upload",
|
Category: taskCategoryUpload,
|
||||||
MaxRetry: 3,
|
MaxRetry: 3,
|
||||||
Queue: "default",
|
Queue: taskQueueDefault,
|
||||||
}
|
}
|
||||||
|
|
||||||
// RebuildUploadStatsHandler rebuilds incremental upload stats from active upload records.
|
// RebuildUploadStatsHandler rebuilds incremental upload stats from active upload records.
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ var StorageMigrationMeta = contracts.TaskMetaDTO{
|
|||||||
Name: StorageMigrationTask,
|
Name: StorageMigrationTask,
|
||||||
DisplayName: "迁移文件存储",
|
DisplayName: "迁移文件存储",
|
||||||
Description: "将活动存储中的文件迁移到待切换的目标存储,迁移期间文件系统保持只读",
|
Description: "将活动存储中的文件迁移到待切换的目标存储,迁移期间文件系统保持只读",
|
||||||
Category: "upload",
|
Category: taskCategoryUpload,
|
||||||
MaxRetry: 3,
|
MaxRetry: 3,
|
||||||
Queue: "default",
|
Queue: taskQueueDefault,
|
||||||
Params: []contracts.TaskParamDTO{
|
Params: []contracts.TaskParamDTO{
|
||||||
{
|
{
|
||||||
Name: "target",
|
Name: "target",
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 上传域任务的通用元数据常量(TaskMetaDTO Category/Queue 复用)
|
||||||
|
const (
|
||||||
|
taskCategoryUpload = "upload"
|
||||||
|
taskQueueDefault = "default"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// WarmImageCacheTask 图片压缩缓存预热任务标识
|
// WarmImageCacheTask 图片压缩缓存预热任务标识
|
||||||
WarmImageCacheTask = "upload:warm_image_cache"
|
WarmImageCacheTask = "upload:warm_image_cache"
|
||||||
@@ -31,9 +37,9 @@ var WarmImageCacheMeta = contracts.TaskMetaDTO{
|
|||||||
Name: WarmImageCacheTask,
|
Name: WarmImageCacheTask,
|
||||||
DisplayName: "预热图片压缩缓存",
|
DisplayName: "预热图片压缩缓存",
|
||||||
Description: "串行将文件管理中的图片转换为指定质量的 WebP 并写入永久缓存",
|
Description: "串行将文件管理中的图片转换为指定质量的 WebP 并写入永久缓存",
|
||||||
Category: "upload",
|
Category: taskCategoryUpload,
|
||||||
MaxRetry: 3,
|
MaxRetry: 3,
|
||||||
Queue: "default",
|
Queue: taskQueueDefault,
|
||||||
Params: []contracts.TaskParamDTO{
|
Params: []contracts.TaskParamDTO{
|
||||||
{
|
{
|
||||||
Name: "quality",
|
Name: "quality",
|
||||||
|
|||||||
@@ -77,8 +77,9 @@ func ValidateAndNormalizePayload(asynqTaskType string, payload []byte) ([]byte,
|
|||||||
type contextKey string
|
type contextKey string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
taskIDKey contextKey = "task_execution_task_id"
|
taskIDKey contextKey = "task_execution_task_id"
|
||||||
traceEnvelopeVersion = 1
|
|
||||||
|
traceEnvelopeVersion = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
type traceEnvelope struct {
|
type traceEnvelope struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user