summaryrefslogtreecommitdiff
path: root/internal/media/prunemeta.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/media/prunemeta.go')
-rw-r--r--internal/media/prunemeta.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/internal/media/prunemeta.go b/internal/media/prunemeta.go
index 69d79b8d9..19fbb7e7e 100644
--- a/internal/media/prunemeta.go
+++ b/internal/media/prunemeta.go
@@ -20,6 +20,7 @@ package media
import (
"context"
+ "errors"
"codeberg.org/gruf/go-store/v2/storage"
"github.com/superseriousbusiness/gotosocial/internal/db"
@@ -28,17 +29,23 @@ import (
)
func (m *manager) PruneAllMeta(ctx context.Context) (int, error) {
- var totalPruned int
- var maxID string
- var attachments []*gtsmodel.MediaAttachment
- var err error
+ var (
+ totalPruned int
+ maxID string
+ )
+
+ for {
+ // select "selectPruneLimit" headers / avatars at a time for pruning
+ attachments, err := m.db.GetAvatarsAndHeaders(ctx, maxID, selectPruneLimit)
+ if err != nil && !errors.Is(err, db.ErrNoEntries) {
+ return totalPruned, err
+ } else if len(attachments) == 0 {
+ break
+ }
- // select 20 attachments at a time and prune them
- for attachments, err = m.db.GetAvatarsAndHeaders(ctx, maxID, selectPruneLimit); err == nil && len(attachments) != 0; attachments, err = m.db.GetAvatarsAndHeaders(ctx, maxID, selectPruneLimit) {
// use the id of the last attachment in the slice as the next 'maxID' value
- l := len(attachments)
- log.Tracef("PruneAllMeta: got %d attachments with maxID < %s", l, maxID)
- maxID = attachments[l-1].ID
+ log.Tracef("PruneAllMeta: got %d attachments with maxID < %s", len(attachments), maxID)
+ maxID = attachments[len(attachments)-1].ID
// prune each attachment that meets one of the following criteria:
// - has no owning account in the database
@@ -56,11 +63,6 @@ func (m *manager) PruneAllMeta(ctx context.Context) (int, error) {
}
}
- // make sure we don't have a real error when we leave the loop
- if err != nil && err != db.ErrNoEntries {
- return totalPruned, err
- }
-
log.Infof("PruneAllMeta: finished pruning avatars + headers: pruned %d entries", totalPruned)
return totalPruned, nil
}