mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Addresses P1 and P2 from code review on the RWMutex commit: P1 — Stream handlers now snapshot config under RLock before streaming: - handleDiffStream: clone Targets map to prevent concurrent map panic - handleCheckStream, handleAuditStream: snapshot source/projectRoot - handleUpdateStream: snapshot source (per-item Lock already correct) P2 — All read handlers now use narrow snapshot instead of defer RUnlock: - RLock → copy needed fields to locals → RUnlock → do work with locals - Prevents slow I/O (git fetch, version check, audit scan) from blocking the auto-reload middleware's exclusive Lock on concurrent requests Other changes: - computeTargetDiff takes source parameter (no more s.cfg.Source access) - Add cloneTargets() helper for safe map copying - Add writeOpsLogTo/writeAuditLogTo for lock-free oplog writes
29 lines
567 B
Go
29 lines
567 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"skillshare/internal/hub"
|
|
)
|
|
|
|
func (s *Server) handleHubIndex(w http.ResponseWriter, r *http.Request) {
|
|
// Snapshot config under RLock, then release before I/O.
|
|
s.mu.RLock()
|
|
sourcePath := s.cfg.Source
|
|
projectRoot := s.projectRoot
|
|
s.mu.RUnlock()
|
|
|
|
if projectRoot != "" {
|
|
sourcePath = filepath.Join(projectRoot, ".skillshare", "skills")
|
|
}
|
|
|
|
idx, err := hub.BuildIndex(sourcePath, false, false)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
|
|
writeJSON(w, idx)
|
|
}
|