Add dependency and dependent counts to bd list JSON output (#198)
When using `bd list --json`, each issue now includes: - `dependency_count`: Number of issues this issue depends on - `dependent_count`: Number of issues that depend on this issue This provides quick access to dependency relationship counts without needing to fetch full dependency lists or run multiple bd show commands. Performance: - Uses single bulk query (GetDependencyCounts) instead of N individual queries - Overhead: ~26% for 500 issues (24ms vs 19ms baseline) - Avoids N+1 query problem that would have caused 2.2x slowdown Implementation: - Added GetDependencyCounts() to Storage interface for bulk counting - Efficient SQLite query using UNION ALL + GROUP BY - Memory storage implementation for testing - Moved IssueWithCounts to types package to avoid duplication - Both RPC and direct modes use optimized bulk query Tests: - Added comprehensive tests for GetDependencyCounts - Tests cover: normal operation, empty list, nonexistent IDs - All existing tests continue to pass Backwards compatible: JSON structure is additive, all original fields preserved. Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
21ab565819
commit
c65cfa1ebd
@@ -555,6 +555,46 @@ func (m *MemoryStorage) GetDependents(ctx context.Context, issueID string) ([]*t
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// GetDependencyCounts returns dependency and dependent counts for multiple issues
|
||||
func (m *MemoryStorage) GetDependencyCounts(ctx context.Context, issueIDs []string) (map[string]*types.DependencyCounts, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
result := make(map[string]*types.DependencyCounts)
|
||||
|
||||
// Initialize all requested IDs with zero counts
|
||||
for _, id := range issueIDs {
|
||||
result[id] = &types.DependencyCounts{
|
||||
DependencyCount: 0,
|
||||
DependentCount: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// Build a set for quick lookup
|
||||
idSet := make(map[string]bool)
|
||||
for _, id := range issueIDs {
|
||||
idSet[id] = true
|
||||
}
|
||||
|
||||
// Count dependencies (issues that this issue depends on)
|
||||
for _, id := range issueIDs {
|
||||
if deps, exists := m.dependencies[id]; exists {
|
||||
result[id].DependencyCount = len(deps)
|
||||
}
|
||||
}
|
||||
|
||||
// Count dependents (issues that depend on this issue)
|
||||
for _, deps := range m.dependencies {
|
||||
for _, dep := range deps {
|
||||
if idSet[dep.DependsOnID] {
|
||||
result[dep.DependsOnID].DependentCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetDependencyRecords gets dependency records for an issue
|
||||
func (m *MemoryStorage) GetDependencyRecords(ctx context.Context, issueID string) ([]*types.Dependency, error) {
|
||||
m.mu.RLock()
|
||||
|
||||
Reference in New Issue
Block a user