模块命名变更
This commit is contained in:
@@ -5,9 +5,9 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/service"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/service"
|
||||
)
|
||||
|
||||
// RepoHandler 仓库API处理器
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/service"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/service"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// StatsHandler 统计API处理器
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// TaskHandler 任务API处理器
|
||||
|
||||
@@ -3,12 +3,12 @@ package api
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
_ "github.com/gitcodestatic/gitcodestatic/docs"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/api/handlers"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/service"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
_ "github.com/hanxuanyu/gitcodestatic/docs"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/api/handlers"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/service"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
httpSwagger "github.com/swaggo/http-swagger"
|
||||
)
|
||||
|
||||
|
||||
12
internal/cache/file_cache.go
vendored
12
internal/cache/file_cache.go
vendored
@@ -8,9 +8,9 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// FileCache 基于文件+DB的缓存实现
|
||||
@@ -66,12 +66,12 @@ func (c *FileCache) Get(ctx context.Context, cacheKey string) (*models.StatsResu
|
||||
}
|
||||
|
||||
// Set 设置缓存
|
||||
func (c *FileCache) Set(ctx context.Context, repoID int64, branch string, constraint *models.StatsConstraint,
|
||||
func (c *FileCache) Set(ctx context.Context, repoID int64, branch string, constraint *models.StatsConstraint,
|
||||
commitHash string, stats *models.Statistics) error {
|
||||
|
||||
|
||||
// 生成缓存键
|
||||
cacheKey := GenerateCacheKey(repoID, branch, constraint, commitHash)
|
||||
|
||||
|
||||
// 保存统计结果到文件
|
||||
resultPath := filepath.Join(c.statsDir, cacheKey+".json.gz")
|
||||
if err := c.saveStatsToFile(stats, resultPath); err != nil {
|
||||
|
||||
4
internal/cache/key.go
vendored
4
internal/cache/key.go
vendored
@@ -5,13 +5,13 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
)
|
||||
|
||||
// GenerateCacheKey 生成缓存键
|
||||
func GenerateCacheKey(repoID int64, branch string, constraint *models.StatsConstraint, commitHash string) string {
|
||||
var constraintStr string
|
||||
|
||||
|
||||
if constraint != nil {
|
||||
if constraint.Type == models.ConstraintTypeDateRange {
|
||||
constraintStr = fmt.Sprintf("dr_%s_%s", constraint.From, constraint.To)
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
)
|
||||
|
||||
// CmdGitManager 基于git命令的实现
|
||||
|
||||
@@ -3,7 +3,7 @@ package git
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
)
|
||||
|
||||
// Manager Git管理器接口
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/worker"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/worker"
|
||||
)
|
||||
|
||||
// RepoService 仓库服务
|
||||
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/cache"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/worker"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/cache"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/worker"
|
||||
)
|
||||
|
||||
// StatsService 统计服务
|
||||
@@ -34,9 +34,9 @@ func NewStatsService(store storage.Store, queue *worker.Queue, fileCache *cache.
|
||||
|
||||
// CalculateRequest 统计请求
|
||||
type CalculateRequest struct {
|
||||
RepoID int64 `json:"repo_id"`
|
||||
Branch string `json:"branch"`
|
||||
Constraint *models.StatsConstraint `json:"constraint"`
|
||||
RepoID int64 `json:"repo_id"`
|
||||
Branch string `json:"branch"`
|
||||
Constraint *models.StatsConstraint `json:"constraint"`
|
||||
}
|
||||
|
||||
// Calculate 触发统计计算
|
||||
|
||||
@@ -3,8 +3,8 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// TaskService 任务服务
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
)
|
||||
|
||||
// Calculator 统计计算器
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/cache"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/stats"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/cache"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/stats"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// CloneHandler 克隆任务处理器
|
||||
@@ -301,7 +301,7 @@ func (h *StatsHandler) Handle(ctx context.Context, task *models.Task) error {
|
||||
if cached != nil {
|
||||
// 缓存命中,直接返回
|
||||
logger.Logger.Info().Str("cache_key", cacheKey).Msg("cache hit during stats calculation")
|
||||
|
||||
|
||||
result := models.TaskResult{
|
||||
CacheKey: cacheKey,
|
||||
Message: "cache hit",
|
||||
@@ -310,7 +310,7 @@ func (h *StatsHandler) Handle(ctx context.Context, task *models.Task) error {
|
||||
resultStr := string(resultJSON)
|
||||
task.Result = &resultStr
|
||||
h.store.Tasks().Update(ctx, task)
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// Pool Worker池
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// Queue 任务队列
|
||||
@@ -40,7 +40,7 @@ func (q *Queue) Enqueue(ctx context.Context, task *models.Task) error {
|
||||
Int64("repo_id", task.RepoID).
|
||||
Str("task_type", task.TaskType).
|
||||
Msg("task already exists, returning existing task")
|
||||
|
||||
|
||||
task.ID = existing.ID
|
||||
task.Status = existing.Status
|
||||
task.CreatedAt = existing.CreatedAt
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// TaskHandler 任务处理器接口
|
||||
@@ -121,7 +121,7 @@ func (w *Worker) handleTask(ctx context.Context, task *models.Task) {
|
||||
|
||||
// 执行任务
|
||||
err := handler.Handle(taskCtx, task)
|
||||
|
||||
|
||||
duration := time.Since(startTime)
|
||||
|
||||
if err != nil {
|
||||
@@ -133,7 +133,7 @@ func (w *Worker) handleTask(ctx context.Context, task *models.Task) {
|
||||
Str("task_type", task.TaskType).
|
||||
Int64("duration_ms", duration.Milliseconds()).
|
||||
Msg("task failed")
|
||||
|
||||
|
||||
w.store.Tasks().UpdateStatus(ctx, task.ID, models.TaskStatusFailed, &errMsg)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user