feat: 并发文件审查,可配置并行度
This commit is contained in:
+19
-4
@@ -38,9 +38,10 @@ func (h *ReviewHandler) Review(c *gin.Context) {
|
||||
|
||||
// Parse request
|
||||
var req struct {
|
||||
Base string `json:"base" binding:"required"`
|
||||
Head string `json:"head" binding:"required"`
|
||||
TopN *int `json:"top_n"`
|
||||
Base string `json:"base" binding:"required"`
|
||||
Head string `json:"head" binding:"required"`
|
||||
TopN *int `json:"top_n"`
|
||||
Concurrency *int `json:"concurrency"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "base and head are required"})
|
||||
@@ -61,6 +62,20 @@ func (h *ReviewHandler) Review(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Determine concurrency: request value > settings default (5)
|
||||
concurrency := 5
|
||||
if req.Concurrency != nil {
|
||||
concurrency = *req.Concurrency
|
||||
} else {
|
||||
var concStr string
|
||||
h.db.QueryRow(`SELECT value FROM settings WHERE key = 'review.concurrency'`).Scan(&concStr)
|
||||
if concStr != "" {
|
||||
if n, err := strconv.Atoi(concStr); err == nil && n > 0 {
|
||||
concurrency = n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set SSE headers
|
||||
c.Header("Content-Type", "text/event-stream")
|
||||
c.Header("Cache-Control", "no-cache")
|
||||
@@ -84,7 +99,7 @@ func (h *ReviewHandler) Review(c *gin.Context) {
|
||||
h.db.Exec(`UPDATE repositories SET last_used = datetime('now') WHERE id = ?`, id)
|
||||
|
||||
// Run AI review
|
||||
reviewResult, err := services.GenerateReview(h.db, localPath, req.Base, req.Head, topN, sendEvent)
|
||||
reviewResult, err := services.GenerateReview(h.db, localPath, req.Base, req.Head, topN, concurrency, sendEvent)
|
||||
if err != nil {
|
||||
sendEvent("error", map[string]interface{}{"message": err.Error()})
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user