From 013ccce576dd8e609c24f4a0ac7bf08ebe19eb66 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Fri, 27 Feb 2026 10:23:55 +0000 Subject: [PATCH] fix: short-circuit pregen when cache is unavailable instead of wasting API call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove pregenFetch fallback that made a full API call but discarded the result. When DBPath() or cache.Open() fails, log a warning and return nil immediately — no pointless 20-minute network round-trip. Fixes #77 Co-Authored-By: Grey Newell Co-Authored-By: Claude Sonnet 4.6 Co-authored-by: claude[bot] --- cmd/pregen.go | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/cmd/pregen.go b/cmd/pregen.go index f187037..53c43fe 100644 --- a/cmd/pregen.go +++ b/cmd/pregen.go @@ -61,14 +61,14 @@ func pregenHandler(cmd *cobra.Command, args []string) error { // Open cache dbPath, err := config.DBPath() if err != nil { - logFn("[warn] cannot open cache: %v", err) - return pregenFetch(cfg, proj, logFn) + logFn("[warn] cannot open cache, skipping pregen: %v", err) + return nil } store, err := cache.Open(dbPath) if err != nil { - logFn("[warn] cache open error: %v", err) - return pregenFetch(cfg, proj, logFn) + logFn("[warn] cache open error, skipping pregen: %v", err) + return nil } defer store.Close() @@ -111,25 +111,3 @@ func pregenHandler(cmd *cobra.Command, args []string) error { logFn("[debug] pregen complete: graph cached for %s", proj.Name) return nil } - -// pregenFetch runs the API fetch without a cache (fallback when DB is unavailable). -func pregenFetch(cfg *config.Config, proj *project.Info, logFn func(string, ...interface{})) error { - ctx, cancel := context.WithTimeout(context.Background(), 20*time.Minute) - defer cancel() - - zipData, truncated, err := zip.RepoZip(proj.RootDir) - if err != nil { - logFn("[warn] zip error: %v", err) - return nil - } - if truncated { - logFn("[warn] repo zip truncated at 10 MB limit — large repos may produce incomplete graph analysis") - } - - apiClient := api.New(cfg.BaseURL, cfg.APIKey, debug, logFn) - _, err = fetchGraphWithCircularDeps(ctx, apiClient, proj.Name, zipData, logFn) - if err != nil { - logFn("[warn] API error: %v", err) - } - return nil -}