beads/internal/storage/dolt/delete_cache_test.go
beads/crew/lizzy b378c1a983 fix: avoid Dolt joinIter hangs in GetReadyWork blocker computation
Three changes to improve bd ready performance on databases with many wisps:

1. Replace correlated NOT EXISTS subquery with JOIN (deferred parent
   exclusion, GH#1190) with pre-computed ID set using separate
   single-table queries — consistent with the pattern used by
   computeBlockedIDs to avoid Dolt joinIter panics.

2. Add includeWisps parameter to computeBlockedIDs. When false (default
   for bd ready without --include-ephemeral), skip scanning wisps and
   wisp_dependencies tables entirely. Verified zero cross-table blocking
   deps exist (issues only blocked by issues, wisps only by wisps).
   Reduces data scanned from ~50K rows to ~500 rows.

3. Cache-aware: a full (wisps-included) cached result satisfies
   issues-only requests; invalidation clears the new flag.

Root cause of bd ready timeouts: the hq database has 18K+ wisps and
33K+ wisp_dependencies. computeBlockedIDs was scanning all of them
even when bd ready only displays non-ephemeral issues.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 14:36:35 -08:00

78 lines
2.4 KiB
Go

package dolt
import (
"testing"
"github.com/steveyegge/beads/internal/types"
)
// TestDeleteIssue_InvalidatesBlockedCache verifies that DeleteIssue clears the
// blocked-IDs cache so that subsequent bd-ready/bd-blocked calls recompute.
func TestDeleteIssue_InvalidatesBlockedCache(t *testing.T) {
store, cleanup := setupTestStore(t)
defer cleanup()
ctx, cancel := testContext(t)
defer cancel()
// Create two issues with a dependency edge
a := &types.Issue{Title: "parent", Status: types.StatusOpen, Priority: 3, IssueType: types.TypeTask}
b := &types.Issue{Title: "child", Status: types.StatusOpen, Priority: 3, IssueType: types.TypeTask}
if err := store.CreateIssue(ctx, a, "test"); err != nil {
t.Fatalf("CreateIssue(a): %v", err)
}
if err := store.CreateIssue(ctx, b, "test"); err != nil {
t.Fatalf("CreateIssue(b): %v", err)
}
dep := &types.Dependency{IssueID: b.ID, DependsOnID: a.ID, Type: "blocks"}
if err := store.AddDependency(ctx, dep, "test"); err != nil {
t.Fatalf("AddDependency: %v", err)
}
// Prime the cache by computing blocked IDs
if _, err := store.computeBlockedIDs(ctx, true); err != nil {
t.Fatalf("computeBlockedIDs: %v", err)
}
if !store.blockedIDsCached {
t.Fatal("expected blockedIDsCached=true after computeBlockedIDs")
}
// Delete the parent — should invalidate cache
if err := store.DeleteIssue(ctx, a.ID); err != nil {
t.Fatalf("DeleteIssue: %v", err)
}
if store.blockedIDsCached {
t.Error("expected blockedIDsCached=false after DeleteIssue")
}
}
// TestDeleteIssues_InvalidatesBlockedCache verifies that batch delete clears
// the blocked-IDs cache.
func TestDeleteIssues_InvalidatesBlockedCache(t *testing.T) {
store, cleanup := setupTestStore(t)
defer cleanup()
ctx, cancel := testContext(t)
defer cancel()
a := &types.Issue{Title: "issue-a", Status: types.StatusOpen, Priority: 3, IssueType: types.TypeTask}
if err := store.CreateIssue(ctx, a, "test"); err != nil {
t.Fatalf("CreateIssue: %v", err)
}
// Prime the cache
if _, err := store.computeBlockedIDs(ctx, true); err != nil {
t.Fatalf("computeBlockedIDs: %v", err)
}
if !store.blockedIDsCached {
t.Fatal("expected blockedIDsCached=true after computeBlockedIDs")
}
// Batch delete
if _, err := store.DeleteIssues(ctx, []string{a.ID}, false, true, false); err != nil {
t.Fatalf("DeleteIssues: %v", err)
}
if store.blockedIDsCached {
t.Error("expected blockedIDsCached=false after DeleteIssues")
}
}