Compare commits
1 Commits
4538d59b1d
...
f067c13d67
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f067c13d67 |
@@ -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
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user