Fix N+1 query pattern in export operations (bd-rcmg)

**Problem**: Export operations called GetLabels() and GetIssueComments()
in a loop for each issue, creating N+1 query pattern. For 100 issues
this created 201 queries instead of 3-5.

**Solution**:
- Added GetCommentsForIssues() batch method to storage interface
- Implemented batch method in SQLite and memory storage backends
- Updated handleExport() and triggerExport() to use batch queries
- Added comprehensive tests for batch operations

**Impact**: Query count reduced from ~201 to ~3-5 for 100 issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-23 19:53:44 -08:00
parent 9d2dadbe87
commit 9c6b37500c
5 changed files with 239 additions and 31 deletions

View File

@@ -912,6 +912,19 @@ func (m *MemoryStorage) GetIssueComments(ctx context.Context, issueID string) ([
return m.comments[issueID], nil
}
func (m *MemoryStorage) GetCommentsForIssues(ctx context.Context, issueIDs []string) (map[string][]*types.Comment, error) {
m.mu.RLock()
defer m.mu.RUnlock()
result := make(map[string][]*types.Comment)
for _, issueID := range issueIDs {
if comments, exists := m.comments[issueID]; exists {
result[issueID] = comments
}
}
return result, nil
}
func (m *MemoryStorage) GetStatistics(ctx context.Context) (*types.Statistics, error) {
m.mu.RLock()
defer m.mu.RUnlock()