fix: Post-PR #8 critical improvements (bd-64, bd-65, bd-66, bd-67)
This commit addresses all critical follow-up issues identified in the code review of PR #8 (atomic counter implementation). ## bd-64: Fix SyncAllCounters performance bottleneck (P0) - Replace SyncAllCounters() on every CreateIssue with lazy initialization - Add ensureCounterInitialized() that only scans prefix-specific issues on first use - Performance improvement: O(n) full table scan → O(1) for subsequent creates - Add comprehensive tests in lazy_init_test.go ## bd-65: Add migration for issue_counters table (P1) - Add migrateIssueCountersTable() similar to migrateDirtyIssuesTable() - Checks if table is empty and syncs from existing issues on first open - Handles both fresh databases and migrations from old databases - Add comprehensive tests in migration_test.go (3 scenarios) ## bd-66: Make import counter sync failure fatal (P1) - Change SyncAllCounters() failure from warning to fatal error in import - Prevents ID collisions when counter sync fails - Data integrity > convenience ## bd-67: Update test comments (P2) - Update TestMultiProcessIDGeneration comments to reflect fix is in place - Change "With the bug, we expect errors" → "After the fix, all should succeed" All tests pass. Atomic counter implementation is now production-ready. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -460,9 +460,9 @@ func TestMultiProcessIDGeneration(t *testing.T) {
|
||||
ids[res.id] = true
|
||||
}
|
||||
|
||||
// With the bug, we expect UNIQUE constraint errors
|
||||
// After the fix (atomic counter), all operations should succeed without errors
|
||||
if len(errors) > 0 {
|
||||
t.Logf("Got %d errors (expected with current implementation):", len(errors))
|
||||
t.Errorf("Expected no errors with atomic counter fix, got %d:", len(errors))
|
||||
for _, err := range errors {
|
||||
t.Logf(" - %v", err)
|
||||
}
|
||||
@@ -470,13 +470,9 @@ func TestMultiProcessIDGeneration(t *testing.T) {
|
||||
|
||||
t.Logf("Successfully created %d unique issues out of %d attempts", len(ids), numProcesses)
|
||||
|
||||
// After the fix, all should succeed
|
||||
// All issues should be created successfully with unique IDs
|
||||
if len(ids) != numProcesses {
|
||||
t.Errorf("Expected %d unique IDs, got %d", numProcesses, len(ids))
|
||||
}
|
||||
|
||||
if len(errors) > 0 {
|
||||
t.Errorf("Expected no errors, got %d", len(errors))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user