summaryrefslogtreecommitdiff
path: root/internal/media
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-02-13 21:19:51 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-13 20:19:51 +0000
commit561ad71e58189d1daea28ec50cc9d4bac82dcfec (patch)
treee0286a51ab64fd971a8f2ebd58bacc4a59f8e87e /internal/media
parent[performance] processing media and scheduled jobs improvements (#1482) (diff)
downloadgotosocial-561ad71e58189d1daea28ec50cc9d4bac82dcfec.tar.xz
[bugfix] Fix up `error getting account avatar/header` errors, other small fixes (#1496)
* start fiddling with media + account queries a little * initialize state when pruning * allow for unsetting remote media make sure to wait til media loaded fix silly tiny bug * move comment a bit for readability * slight reformat of fetchRemoteAccount{Avatar,Header} * fix issue after rebase * slightly neaten up logic of avatar/header media handling * remove log prefix (callername log field handles this) --------- Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/media')
-rw-r--r--internal/media/prune.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/internal/media/prune.go b/internal/media/prune.go
index 3509e249d..bb0993759 100644
--- a/internal/media/prune.go
+++ b/internal/media/prune.go
@@ -119,14 +119,24 @@ func (m *manager) PruneUnusedRemote(ctx context.Context, dry bool) (int, error)
for attachments, err = m.state.DB.GetAvatarsAndHeaders(ctx, maxID, selectPruneLimit); err == nil && len(attachments) != 0; attachments, err = m.state.DB.GetAvatarsAndHeaders(ctx, maxID, selectPruneLimit) {
maxID = attachments[len(attachments)-1].ID // use the id of the last attachment in the slice as the next 'maxID' value
- // Prune each attachment that meets one of the following criteria:
- // - Has no owning account in the database.
- // - Is a header but isn't the owning account's current header.
- // - Is an avatar but isn't the owning account's current avatar.
for _, attachment := range attachments {
- if attachment.Account == nil ||
- (*attachment.Header && attachment.ID != attachment.Account.HeaderMediaAttachmentID) ||
- (*attachment.Avatar && attachment.ID != attachment.Account.AvatarMediaAttachmentID) {
+ // Retrieve owning account if possible.
+ var account *gtsmodel.Account
+ if accountID := attachment.AccountID; accountID != "" {
+ account, err = m.state.DB.GetAccountByID(ctx, attachment.AccountID)
+ if err != nil && !errors.Is(err, db.ErrNoEntries) {
+ // Only return on a real error.
+ return 0, fmt.Errorf("PruneUnusedRemote: error fetching account with id %s: %w", accountID, err)
+ }
+ }
+
+ // Prune each attachment that meets one of the following criteria:
+ // - Has no owning account in the database.
+ // - Is a header but isn't the owning account's current header.
+ // - Is an avatar but isn't the owning account's current avatar.
+ if account == nil ||
+ (*attachment.Header && attachment.ID != account.HeaderMediaAttachmentID) ||
+ (*attachment.Avatar && attachment.ID != account.AvatarMediaAttachmentID) {
if err := f(ctx, attachment); err != nil {
return totalPruned, err
}