summaryrefslogtreecommitdiff
path: root/internal/media/prunemeta.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-12-12 11:22:19 +0000
committerLibravatar GitHub <noreply@github.com>2022-12-12 12:22:19 +0100
commit58c87bdd7f37e80a57c4802e95eb6c572ccffed4 (patch)
treeecfa90c1249adbd02b386f624b9dbf3c405cafd6 /internal/media/prunemeta.go
parent[chore]: Bump golang.org/x/image from 0.1.0 to 0.2.0 (#1252) (diff)
downloadgotosocial-58c87bdd7f37e80a57c4802e95eb6c572ccffed4.tar.xz
[feature] allow uncaching of other media types (#1234)
* simplify pruneRemote, remove unncecessary media trace logging, update RemoteOlderThan() to include headers/avis Signed-off-by: kim <grufwub@gmail.com> * cleanup pruneallmeta, add remote header to pruneremote tests Signed-off-by: kim <grufwub@gmail.com> * fix olderthan duration additions Signed-off-by: kim <grufwub@gmail.com> * fix broken test now that test model header changed Signed-off-by: kim <grufwub@gmail.com> * instead use new remote test account for new header model Signed-off-by: kim <grufwub@gmail.com> * use newer generated ULID for remote_account_3 to ensure it is sorted last Signed-off-by: kim <grufwub@gmail.com> * reorganize serialized keys to match expected test account model order Signed-off-by: kim <grufwub@gmail.com> Signed-off-by: kim <grufwub@gmail.com>
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
}