mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 11:17:28 -06:00
[feature] Cleanup unattached local media (#680)
* add localUnattached db function * add parseOlderThan util function * add pruneunusedlocalattachments to media manager * add unusedlocal pruning to schedule + admin call * set number of days to keep as a const * fix test
This commit is contained in:
parent
07620acc0e
commit
9e7d022a06
9 changed files with 253 additions and 10 deletions
|
|
@ -21,7 +21,6 @@ package media
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"codeberg.org/gruf/go-store/storage"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
|
@ -32,15 +31,10 @@ import (
|
|||
func (m *manager) PruneAllRemote(ctx context.Context, olderThanDays int) (int, error) {
|
||||
var totalPruned int
|
||||
|
||||
// convert days into a duration string
|
||||
olderThanHoursString := fmt.Sprintf("%dh", olderThanDays*24)
|
||||
// parse the duration string into a duration
|
||||
olderThanHours, err := time.ParseDuration(olderThanHoursString)
|
||||
olderThan, err := parseOlderThan(olderThanDays)
|
||||
if err != nil {
|
||||
return totalPruned, fmt.Errorf("PruneAllRemote: %d", err)
|
||||
return totalPruned, fmt.Errorf("PruneAllRemote: error parsing olderThanDays %d: %s", olderThanDays, err)
|
||||
}
|
||||
// 'subtract' that from the time now to give our threshold
|
||||
olderThan := time.Now().Add(-olderThanHours)
|
||||
logrus.Infof("PruneAllRemote: pruning media older than %s", olderThan)
|
||||
|
||||
// select 20 attachments at a time and prune them
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue