added enhanced DB functions

This commit is contained in:
2025-04-08 18:48:34 -04:00
parent 7599665e4c
commit 18d8b6eee2
4 changed files with 45 additions and 0 deletions
+23
View File
@@ -2,6 +2,7 @@ package helpers
import (
"database/sql"
"fmt"
"os"
"path/filepath"
"sync"
@@ -62,6 +63,28 @@ func SetLastSubmission(userID string) error {
return err
}
func RemoveUserSubmittions(userId string) error {
_, err := db.Exec(`
DELETE FROM suggestion_cooldowns WHERE user_id = ?
`, userId)
return err
}
func SweepExpiredSubmissions(expiration time.Duration) error {
cutoff := time.Now().Add(-expiration)
result, err := db.Exec("DELETE FROM suggestion_cooldowns WHERE last_submission <= ?", cutoff)
if err != nil {
return fmt.Errorf("failed to sweep expired submissions: %w", err)
}
rowsDeleted, _ := result.RowsAffected()
fmt.Printf("Swept %d expired entries from suggestion_cooldowns\n", rowsDeleted)
return nil
}
func CloseDB() error {
if db != nil {
return db.Close()