Implement queue pruning and message rotation (closes #40) #67

Merged
sneak merged 6 commits from feat/queue-pruning into main 2026-03-10 15:37:34 +01:00
3 changed files with 1 additions and 38 deletions
Showing only changes of commit 291be0c701 - Show all commits

View File

@@ -1789,8 +1789,7 @@ skew issues) and simpler than UUIDs (integer comparison vs. string comparison).
### Data Lifecycle
- **Messages**: Rotated per `MAX_HISTORY` — oldest messages beyond the limit
are pruned periodically per target (channel or DM). Orphaned messages (no
longer referenced by any client queue) are also removed.
are pruned periodically per target (channel or DM).
- **Queue entries**: Pruned automatically when older than `QUEUE_MAX_AGE`
(default 48h).
- **Channels**: Deleted when the last member leaves (ephemeral).

View File

@@ -1118,28 +1118,6 @@ func (database *Database) PruneOldQueueEntries(
return deleted, nil
}
// PruneOrphanedMessages deletes messages that are no
// longer referenced by any client_queues row and returns
// the number of rows removed.
func (database *Database) PruneOrphanedMessages(
ctx context.Context,
) (int64, error) {
res, err := database.conn.ExecContext(ctx,
`DELETE FROM messages WHERE id NOT IN
(SELECT DISTINCT message_id
FROM client_queues)`,
)
if err != nil {
return 0, fmt.Errorf(
"prune orphaned messages: %w", err,
)
}
deleted, _ := res.RowsAffected()
return deleted, nil
}
// RotateChannelMessages enforces MAX_HISTORY per channel
// by deleting the oldest messages beyond the limit for
// each msg_to target. Returns the total number of rows

View File

@@ -245,18 +245,4 @@ func (hdlr *Handlers) pruneQueuesAndMessages(
)
}
}
orphaned, err := hdlr.params.Database.
PruneOrphanedMessages(ctx)
if err != nil {
hdlr.log.Error(
"orphan message cleanup failed",
"error", err,
)
} else if orphaned > 0 {
hdlr.log.Info(
"pruned orphaned messages",
"deleted", orphaned,
)
}
}