Put more things in tx

This commit is contained in:
binwiederhier
2026-03-02 19:58:26 -05:00
parent 8afeb813d9
commit c864a9baeb

View File

@@ -130,12 +130,13 @@ func (s *Store) RemoveSubscriptionsByUserID(userID string) error {
// RemoveExpiredSubscriptions removes all subscriptions that have not been updated for a given time period. // RemoveExpiredSubscriptions removes all subscriptions that have not been updated for a given time period.
func (s *Store) RemoveExpiredSubscriptions(expireAfter time.Duration) error { func (s *Store) RemoveExpiredSubscriptions(expireAfter time.Duration) error {
_, err := s.db.Exec(s.queries.deleteSubscriptionByAge, time.Now().Add(-expireAfter).Unix()) return db.ExecTx(s.db, func(tx *sql.Tx) error {
if err != nil { if _, err := tx.Exec(s.queries.deleteSubscriptionByAge, time.Now().Add(-expireAfter).Unix()); err != nil {
return err
}
_, err := tx.Exec(s.queries.deleteSubscriptionTopicWithoutSubscription)
return err return err
} })
_, err = s.db.Exec(s.queries.deleteSubscriptionTopicWithoutSubscription)
return err
} }
// SetSubscriptionUpdatedAt updates the updated_at timestamp for a subscription by endpoint. This is // SetSubscriptionUpdatedAt updates the updated_at timestamp for a subscription by endpoint. This is