fix: sync counters on every CreateIssue to prevent race conditions

Move counter sync from import to CreateIssue to handle parallel issue creation.
This ensures the counter is always up-to-date before generating new IDs,
preventing collisions when multiple processes create issues concurrently.

Remove unused SyncCounterForPrefix method and its test.
This commit is contained in:
v4rgas
2025-10-13 20:26:43 -03:00
committed by Steve Yegge
parent 367259168d
commit 838d884988
2 changed files with 0 additions and 80 deletions

View File

@@ -107,22 +107,6 @@ func (s *SQLiteStorage) getNextIDForPrefix(ctx context.Context, prefix string) (
return nextID, nil
}
// SyncCounterForPrefix synchronizes the counter to be at least the given value
// This is used after importing issues with explicit IDs to prevent ID collisions
// with subsequently auto-generated IDs
func (s *SQLiteStorage) SyncCounterForPrefix(ctx context.Context, prefix string, minValue int) error {
_, err := s.db.ExecContext(ctx, `
INSERT INTO issue_counters (prefix, last_id)
VALUES (?, ?)
ON CONFLICT(prefix) DO UPDATE SET
last_id = MAX(last_id, ?)
`, prefix, minValue, minValue)
if err != nil {
return fmt.Errorf("failed to sync counter for prefix %s: %w", prefix, err)
}
return nil
}
// SyncAllCounters synchronizes all ID counters based on existing issues in the database
// This scans all issues and updates counters to prevent ID collisions with auto-generated IDs
func (s *SQLiteStorage) SyncAllCounters(ctx context.Context) error {