mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
feat(releases): delete older than x (#924)
* feat: delete releases older than x * check timestamp * incomplete front end changes commiting changes from codespace to not lose them * change to dropdown with options * using int comparisons to avoid nightmares * Revert "using int comparisons to avoid nightmares" This reverts commit dc55966a73e9f6ad79ed28c3a3e0dbe0e35448a6. * suggestions by stacksmash76 come back to discord @stacksmash76 * Curves - a touch of warmth in our pixel realm * replace inline css with tailwind * remove unnecessary comment * align label with dropdown changed first paragraph to something more sensible * change font weight for duration label * padding changes * nitpicky * merged divs where possible * small adjustments for light theme * attempt to fix for postgres * refactor: split into component and add confirmation modal also restyle component * fix: go fmt --------- Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com>
This commit is contained in:
parent
1f76aa38f4
commit
f774831d76
6 changed files with 182 additions and 54 deletions
|
@ -18,6 +18,7 @@ import (
|
|||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type ReleaseRepo struct {
|
||||
|
@ -585,6 +586,40 @@ func (repo *ReleaseRepo) Delete(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (repo *ReleaseRepo) DeleteOlder(ctx context.Context, duration int) error {
|
||||
tx, err := repo.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer tx.Rollback()
|
||||
|
||||
olderThanTimestamp := time.Now().UTC().Add(-time.Duration(duration) * time.Hour)
|
||||
log.Debug().Msgf("Deleting releases older than: %v", olderThanTimestamp)
|
||||
|
||||
result, err := tx.ExecContext(ctx, `DELETE FROM "release" WHERE timestamp < $1`, olderThanTimestamp)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
deletedRows, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error fetching rows affected")
|
||||
}
|
||||
log.Debug().Msgf("Deleted %d rows from release table", deletedRows)
|
||||
|
||||
_, err = tx.ExecContext(ctx, `DELETE FROM release_action_status WHERE release_id NOT IN (SELECT id FROM "release")`)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
return errors.Wrap(err, "error commit transaction delete")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *ReleaseRepo) CanDownloadShow(ctx context.Context, title string, season int, episode int) (bool, error) {
|
||||
// TODO support non season episode shows
|
||||
// if rls.Day > 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue