Commit Graph

4 Commits

Author SHA1 Message Date
beads/crew/dave
ec1a32b9a8 fix(storage): add reconnectMu RLock protection to prevent race condition (#1054)
Add missing reconnectMu.RLock() protection to storage methods that were
vulnerable to the same race condition fixed in GH#607. The FreshnessChecker
can trigger reconnect() which closes s.db while queries are in flight,
causing "database is closed" errors during daemon export operations.

Protected methods:
- labels.go: GetLabelsForIssues (GetLabels intentionally unprotected - called from GetIssue which holds lock)
- comments.go: GetIssueComments, GetCommentsForIssues
- dependencies.go: GetDependencyCounts, GetDependencyRecords, GetAllDependencyRecords, GetDependencyTree, loadDependencyGraph
- config.go: SetConfig, GetConfig, GetAllConfig, DeleteConfig, SetMetadata, GetMetadata
- dirty.go: MarkIssueDirty, GetDirtyIssues, GetDirtyIssueHash, GetDirtyIssueCount
- events.go: GetEvents, GetStatistics, GetMoleculeProgress
- hash.go: All hash methods
- hash_ids.go: GetNextChildID, ensureChildCounterUpdated (getNextChildNumber unprotected - called internally)

Internal helpers called from already-locked contexts intentionally omit
RLock to avoid deadlock (Go's RWMutex doesn't support recursive locking).

Fixes: bd-vx7fp

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/dave
Rig: beads
Role: crew
2026-01-12 18:29:42 -08:00
Steve Yegge
9743b45c6d fix(import): preserve comment created_at timestamps during import (#735)
Comment timestamps were being overwritten with CURRENT_TIMESTAMP during
import, causing infinite sync loops between hosts as each import would
update timestamps.

Added ImportIssueComment() method that accepts and preserves the original
timestamp from JSONL, and updated importComments() to use it.

Closes #735
2025-12-24 12:45:20 -08:00
Steve Yegge
9c6b37500c 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>
2025-11-23 19:53:44 -08:00
Steve Yegge
58f37d05c6 refactor: Split monolithic sqlite.go into focused files (bd-0a43)
Split internal/storage/sqlite/sqlite.go (1050 lines) into focused files
for better maintainability and code discovery:

- store.go (306 lines): SQLiteStorage struct, New() constructor,
  initialization logic, and database utilities (Close, Path, IsClosed,
  UnderlyingDB, UnderlyingConn, CheckpointWAL)

- queries.go (1173 lines): Issue CRUD operations including CreateIssue,
  GetIssue, GetIssueByExternalRef, UpdateIssue, UpdateIssueID,
  CloseIssue, DeleteIssue, DeleteIssues, SearchIssues with all helpers

- config.go (95 lines): Configuration and metadata management (SetConfig,
  GetConfig, GetAllConfig, DeleteConfig, SetMetadata, GetMetadata) plus
  OrphanHandling type definitions

- comments.go (83 lines): Comment operations (AddIssueComment,
  GetIssueComments)

- sqlite.go (31 lines): Package documentation explaining file organization

Additional changes:
- Removed duplicate OrphanHandling definition from ids.go (was causing
  build error with new config.go)

Impact:
- Zero functional changes, all tests pass (2.6s runtime)
- Improved code discovery: easy to locate specific functionality
- Better maintainability: related code grouped logically
- Reduced cognitive load: smaller, focused files

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 19:04:34 -08:00