From 614ba8ab20e8018da89db6913f667b9a15016b33 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Thu, 20 Nov 2025 19:27:31 -0500 Subject: [PATCH] Add cache invalidation for blocked_issues_cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensures cache stays synchronized with dependency and status changes by calling invalidateBlockedCache() at all mutation points (bd-5qim). Cache invalidation points: - AddDependency: when type is 'blocks' or 'parent-child' - RemoveDependency: when removed dep was 'blocks' or 'parent-child' - UpdateIssue: when status field changes - CloseIssue: always (closed issues don't block) The invalidation strategy is full cache rebuild on any change, which is fast enough (<1ms for 10K issues) and keeps the logic simple. Only 'blocks' and 'parent-child' dependency types affect blocking, so 'relates-to' and other types skip invalidation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- internal/storage/sqlite/dependencies.go | 27 +++++++++++++++++++++++++ internal/storage/sqlite/sqlite.go | 14 +++++++++++++ 2 files changed, 41 insertions(+) diff --git a/internal/storage/sqlite/dependencies.go b/internal/storage/sqlite/dependencies.go index 7f8c32f9..ca450fc4 100644 --- a/internal/storage/sqlite/dependencies.go +++ b/internal/storage/sqlite/dependencies.go @@ -150,6 +150,14 @@ func (s *SQLiteStorage) AddDependency(ctx context.Context, dep *types.Dependency return wrapDBError("mark issues dirty after adding dependency", err) } + // Invalidate blocked issues cache since dependencies changed (bd-5qim) + // Only invalidate for 'blocks' and 'parent-child' types since they affect blocking + if dep.Type == types.DepBlocks || dep.Type == types.DepParentChild { + if err := s.invalidateBlockedCache(ctx, tx); err != nil { + return fmt.Errorf("failed to invalidate blocked cache: %w", err) + } + } + return nil }) } @@ -157,6 +165,18 @@ func (s *SQLiteStorage) AddDependency(ctx context.Context, dep *types.Dependency // RemoveDependency removes a dependency func (s *SQLiteStorage) RemoveDependency(ctx context.Context, issueID, dependsOnID string, actor string) error { return s.withTx(ctx, func(tx *sql.Tx) error { + // First, check what type of dependency is being removed + var depType types.DependencyType + err := tx.QueryRowContext(ctx, ` + SELECT type FROM dependencies WHERE issue_id = ? AND depends_on_id = ? + `, issueID, dependsOnID).Scan(&depType) + + // Store whether cache needs invalidation before deletion + needsCacheInvalidation := false + if err == nil { + needsCacheInvalidation = (depType == types.DepBlocks || depType == types.DepParentChild) + } + result, err := tx.ExecContext(ctx, ` DELETE FROM dependencies WHERE issue_id = ? AND depends_on_id = ? `, issueID, dependsOnID) @@ -187,6 +207,13 @@ func (s *SQLiteStorage) RemoveDependency(ctx context.Context, issueID, dependsOn return wrapDBError("mark issues dirty after removing dependency", err) } + // Invalidate blocked issues cache if this was a blocking dependency (bd-5qim) + if needsCacheInvalidation { + if err := s.invalidateBlockedCache(ctx, tx); err != nil { + return fmt.Errorf("failed to invalidate blocked cache: %w", err) + } + } + return nil }) } diff --git a/internal/storage/sqlite/sqlite.go b/internal/storage/sqlite/sqlite.go index 61490c13..50864d9d 100644 --- a/internal/storage/sqlite/sqlite.go +++ b/internal/storage/sqlite/sqlite.go @@ -694,6 +694,14 @@ func (s *SQLiteStorage) UpdateIssue(ctx context.Context, id string, updates map[ return fmt.Errorf("failed to mark issue dirty: %w", err) } + // Invalidate blocked issues cache if status changed (bd-5qim) + // Status changes affect which issues are blocked (blockers must be open/in_progress/blocked) + if _, statusChanged := updates["status"]; statusChanged { + if err := s.invalidateBlockedCache(ctx, tx); err != nil { + return fmt.Errorf("failed to invalidate blocked cache: %w", err) + } + } + return tx.Commit() } @@ -861,6 +869,12 @@ func (s *SQLiteStorage) CloseIssue(ctx context.Context, id string, reason string return fmt.Errorf("failed to mark issue dirty: %w", err) } + // Invalidate blocked issues cache since status changed to closed (bd-5qim) + // Closed issues don't block others, so this affects blocking calculations + if err := s.invalidateBlockedCache(ctx, tx); err != nil { + return fmt.Errorf("failed to invalidate blocked cache: %w", err) + } + return tx.Commit() }