ServeGraph handles v1beta1 GraphService/GetGraph. Returns a minimal graph with one commit per module ref and no edges (no transitive dependencies for our single-module proxy use case).
(w http.ResponseWriter, r *http.Request)
| 246 | // Returns a minimal graph with one commit per module ref and no edges |
| 247 | // (no transitive dependencies for our single-module proxy use case). |
| 248 | func (h *commitServiceHandler) ServeGraph(w http.ResponseWriter, r *http.Request) { |
| 249 | if r.Method != http.MethodPost { |
| 250 | h.logHandlerError(r, w, "method not allowed", http.StatusMethodNotAllowed) |
| 251 | return |
| 252 | } |
| 253 | |
| 254 | body, err := io.ReadAll(r.Body) |
| 255 | if err != nil { |
| 256 | h.badRequest(r, w, "reading body", slog.String("read_error", err.Error())) |
| 257 | return |
| 258 | } |
| 259 | |
| 260 | // Parse GetGraphRequest - handle both v1 and v1beta1 formats: |
| 261 | // v1beta1: field 1 = repeated GetGraphRequest_ResourceRef { ResourceRef, Registry } |
| 262 | isV1 := !strings.Contains(r.URL.Path, "v1beta1") |
| 263 | var refs []moduleRef |
| 264 | if isV1 { |
| 265 | refs = parseGetGraphResourceRefsV1(body) |
| 266 | } else { |
| 267 | refs = parseGetGraphResourceRefs(body) |
| 268 | } |
| 269 | h.hlog(r).LogAttrs(r.Context(), slog.LevelInfo, "handler decision", |
| 270 | slog.String("handler", "ServeGraph"), |
| 271 | slog.String("procedure", "GraphService/GetGraph"), |
| 272 | slog.String("protocol", protocolLabel(isV1)), |
| 273 | slog.Int("refs", len(refs)), |
| 274 | slog.Int("body_bytes", len(body)), |
| 275 | slog.String("branch", "request_parsed"), |
| 276 | ) |
| 277 | if len(refs) == 0 { |
| 278 | // Return empty graph |
| 279 | w.Header().Set("Content-Type", "application/proto") |
| 280 | _, _ = w.Write(nil) |
| 281 | return |
| 282 | } |
| 283 | |
| 284 | type commitInfo struct { |
| 285 | ownerID string |
| 286 | moduleID string |
| 287 | commitID string |
| 288 | owner string |
| 289 | module string |
| 290 | digest []byte |
| 291 | } |
| 292 | commits := make([]commitInfo, 0, len(refs)) |
| 293 | for _, ref := range refs { |
| 294 | key := ref.owner + "/" + ref.module |
| 295 | h.commitMu.RLock() |
| 296 | cached, ok := h.infoCache[key] |
| 297 | h.commitMu.RUnlock() |
| 298 | if ok { |
| 299 | h.hlog(r).LogAttrs(r.Context(), slog.LevelInfo, "handler decision", |
| 300 | slog.String("handler", "ServeGraph"), |
| 301 | slog.String("procedure", "GraphService/GetGraph"), |
| 302 | slog.String("branch", "info_cache_hit"), |
| 303 | slog.String("owner", ref.owner), |
| 304 | slog.String("module", ref.module), |
| 305 | slog.String("repo", ref.module), |
nothing calls this directly
no test coverage detected