Complete bd-164: Fix timestamp-only export deduplication
- Add export_hashes table to track last exported content state - Implement GetExportHash/SetExportHash in storage interface - Update shouldSkipExport to use export_hashes instead of dirty_issues - Call SetExportHash after successful export - Clean up dirty_issues table (remove content_hash column) - Simplify MarkIssueDirty functions (no longer compute hashes) - Update markIssuesDirtyTx signature (remove store parameter) Testing: - Timestamp-only updates are skipped during export ✓ - Real content changes trigger export ✓ - export_hashes table populated correctly ✓ Fixes bd-159, bd-164
This commit is contained in:
@@ -11,22 +11,11 @@ import (
|
||||
// MarkIssueDirty marks an issue as dirty (needs to be exported to JSONL)
|
||||
// This should be called whenever an issue is created, updated, or has dependencies changed
|
||||
func (s *SQLiteStorage) MarkIssueDirty(ctx context.Context, issueID string) error {
|
||||
// Fetch the issue to compute its content hash
|
||||
issue, err := s.GetIssue(ctx, issueID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hash, err := computeIssueContentHash(issue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = s.db.ExecContext(ctx, `
|
||||
INSERT INTO dirty_issues (issue_id, marked_at, content_hash)
|
||||
VALUES (?, ?, ?)
|
||||
ON CONFLICT (issue_id) DO UPDATE SET marked_at = excluded.marked_at, content_hash = excluded.content_hash
|
||||
`, issueID, time.Now(), hash)
|
||||
_, err := s.db.ExecContext(ctx, `
|
||||
INSERT INTO dirty_issues (issue_id, marked_at)
|
||||
VALUES (?, ?)
|
||||
ON CONFLICT (issue_id) DO UPDATE SET marked_at = excluded.marked_at
|
||||
`, issueID, time.Now())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -45,9 +34,9 @@ func (s *SQLiteStorage) MarkIssuesDirty(ctx context.Context, issueIDs []string)
|
||||
|
||||
now := time.Now()
|
||||
stmt, err := tx.PrepareContext(ctx, `
|
||||
INSERT INTO dirty_issues (issue_id, marked_at, content_hash)
|
||||
VALUES (?, ?, ?)
|
||||
ON CONFLICT (issue_id) DO UPDATE SET marked_at = excluded.marked_at, content_hash = excluded.content_hash
|
||||
INSERT INTO dirty_issues (issue_id, marked_at)
|
||||
VALUES (?, ?)
|
||||
ON CONFLICT (issue_id) DO UPDATE SET marked_at = excluded.marked_at
|
||||
`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to prepare statement: %w", err)
|
||||
@@ -55,18 +44,7 @@ func (s *SQLiteStorage) MarkIssuesDirty(ctx context.Context, issueIDs []string)
|
||||
defer func() { _ = stmt.Close() }()
|
||||
|
||||
for _, issueID := range issueIDs {
|
||||
// Fetch issue to compute content hash
|
||||
issue, err := s.GetIssue(ctx, issueID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", issueID, err)
|
||||
}
|
||||
|
||||
hash, err := computeIssueContentHash(issue)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to compute hash for issue %s: %w", issueID, err)
|
||||
}
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, issueID, now, hash); err != nil {
|
||||
if _, err := stmt.ExecContext(ctx, issueID, now); err != nil {
|
||||
return fmt.Errorf("failed to mark issue %s dirty: %w", issueID, err)
|
||||
}
|
||||
}
|
||||
@@ -171,16 +149,16 @@ func (s *SQLiteStorage) GetDirtyIssueCount(ctx context.Context) (int, error) {
|
||||
|
||||
// markIssuesDirtyTx marks multiple issues as dirty within an existing transaction
|
||||
// This is a helper for operations that need to mark issues dirty as part of a larger transaction
|
||||
func markIssuesDirtyTx(ctx context.Context, tx *sql.Tx, store *SQLiteStorage, issueIDs []string) error {
|
||||
func markIssuesDirtyTx(ctx context.Context, tx *sql.Tx, issueIDs []string) error {
|
||||
if len(issueIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
stmt, err := tx.PrepareContext(ctx, `
|
||||
INSERT INTO dirty_issues (issue_id, marked_at, content_hash)
|
||||
VALUES (?, ?, ?)
|
||||
ON CONFLICT (issue_id) DO UPDATE SET marked_at = excluded.marked_at, content_hash = excluded.content_hash
|
||||
INSERT INTO dirty_issues (issue_id, marked_at)
|
||||
VALUES (?, ?)
|
||||
ON CONFLICT (issue_id) DO UPDATE SET marked_at = excluded.marked_at
|
||||
`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to prepare dirty statement: %w", err)
|
||||
@@ -188,18 +166,7 @@ func markIssuesDirtyTx(ctx context.Context, tx *sql.Tx, store *SQLiteStorage, is
|
||||
defer func() { _ = stmt.Close() }()
|
||||
|
||||
for _, issueID := range issueIDs {
|
||||
// Fetch issue to compute content hash
|
||||
issue, err := store.GetIssue(ctx, issueID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", issueID, err)
|
||||
}
|
||||
|
||||
hash, err := computeIssueContentHash(issue)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to compute hash for issue %s: %w", issueID, err)
|
||||
}
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, issueID, now, hash); err != nil {
|
||||
if _, err := stmt.ExecContext(ctx, issueID, now); err != nil {
|
||||
return fmt.Errorf("failed to mark issue %s dirty: %w", issueID, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user