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() }