Skip to content

Commit 914bcc1

Browse files
committed
simplify stale draft deletion sql
1 parent 1a5756a commit 914bcc1

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

internal/conversation/drafts.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package conversation
33
import (
44
"context"
55
"encoding/json"
6-
"fmt"
76
"time"
87

98
"github.com/abhinavxd/libredesk/internal/conversation/models"
@@ -49,10 +48,8 @@ func (m *Manager) DeleteConversationDraft(conversationID int, uuid string, userI
4948

5049
// DeleteStaleDrafts deletes drafts older than the specified retention period.
5150
func (m *Manager) DeleteStaleDrafts(ctx context.Context, retentionPeriod time.Duration) error {
52-
// Format duration as PostgreSQL interval string
53-
intervalStr := fmt.Sprintf("%d seconds", int(retentionPeriod.Seconds()))
54-
55-
res, err := m.q.DeleteStaleDrafts.ExecContext(ctx, intervalStr)
51+
cutoff := time.Now().Add(-retentionPeriod)
52+
res, err := m.q.DeleteStaleDrafts.ExecContext(ctx, cutoff)
5653
if err != nil {
5754
m.lo.Error("error deleting stale drafts", "error", err)
5855
return err

internal/conversation/queries.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,4 +584,4 @@ WHERE conversation_id IN (
584584

585585
-- name: delete-stale-drafts
586586
DELETE FROM conversation_drafts
587-
WHERE created_at < NOW() - $1::interval;
587+
WHERE created_at < $1;

0 commit comments

Comments
 (0)