mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-29 00:23:32 -06:00
[bugfix] fix possible infinite loops in media / emoji cleanup (#2590)
* update media / emoji cleaner funcs to use new paging package, check for same returned maxID * fix other calls of getattachments and getmojis not using paging * use alternative order-by function
This commit is contained in:
parent
0f7a2024c3
commit
c9452f32f3
8 changed files with 158 additions and 119 deletions
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/state"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||
"github.com/uptrace/bun"
|
||||
|
|
@ -326,8 +327,11 @@ func (e *emojiDB) GetEmojisBy(ctx context.Context, domain string, includeDisable
|
|||
return e.GetEmojisByIDs(ctx, emojiIDs)
|
||||
}
|
||||
|
||||
func (e *emojiDB) GetEmojis(ctx context.Context, maxID string, limit int) ([]*gtsmodel.Emoji, error) {
|
||||
var emojiIDs []string
|
||||
func (e *emojiDB) GetEmojis(ctx context.Context, page *paging.Page) ([]*gtsmodel.Emoji, error) {
|
||||
maxID := page.GetMax()
|
||||
limit := page.GetLimit()
|
||||
|
||||
emojiIDs := make([]string, 0, limit)
|
||||
|
||||
q := e.db.NewSelect().
|
||||
Table("emojis").
|
||||
|
|
@ -349,8 +353,11 @@ func (e *emojiDB) GetEmojis(ctx context.Context, maxID string, limit int) ([]*gt
|
|||
return e.GetEmojisByIDs(ctx, emojiIDs)
|
||||
}
|
||||
|
||||
func (e *emojiDB) GetRemoteEmojis(ctx context.Context, maxID string, limit int) ([]*gtsmodel.Emoji, error) {
|
||||
var emojiIDs []string
|
||||
func (e *emojiDB) GetRemoteEmojis(ctx context.Context, page *paging.Page) ([]*gtsmodel.Emoji, error) {
|
||||
maxID := page.GetMax()
|
||||
limit := page.GetLimit()
|
||||
|
||||
emojiIDs := make([]string, 0, limit)
|
||||
|
||||
q := e.db.NewSelect().
|
||||
Table("emojis").
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/state"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||
"github.com/uptrace/bun"
|
||||
|
|
@ -232,7 +233,10 @@ func (m *mediaDB) DeleteAttachment(ctx context.Context, id string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (m *mediaDB) GetAttachments(ctx context.Context, maxID string, limit int) ([]*gtsmodel.MediaAttachment, error) {
|
||||
func (m *mediaDB) GetAttachments(ctx context.Context, page *paging.Page) ([]*gtsmodel.MediaAttachment, error) {
|
||||
maxID := page.GetMax()
|
||||
limit := page.GetLimit()
|
||||
|
||||
attachmentIDs := make([]string, 0, limit)
|
||||
|
||||
q := m.db.NewSelect().
|
||||
|
|
@ -255,7 +259,10 @@ func (m *mediaDB) GetAttachments(ctx context.Context, maxID string, limit int) (
|
|||
return m.GetAttachmentsByIDs(ctx, attachmentIDs)
|
||||
}
|
||||
|
||||
func (m *mediaDB) GetRemoteAttachments(ctx context.Context, maxID string, limit int) ([]*gtsmodel.MediaAttachment, error) {
|
||||
func (m *mediaDB) GetRemoteAttachments(ctx context.Context, page *paging.Page) ([]*gtsmodel.MediaAttachment, error) {
|
||||
maxID := page.GetMax()
|
||||
limit := page.GetLimit()
|
||||
|
||||
attachmentIDs := make([]string, 0, limit)
|
||||
|
||||
q := m.db.NewSelect().
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||
)
|
||||
|
||||
// EmojiAllDomains can be used as the `domain` value in a GetEmojis
|
||||
|
|
@ -47,10 +48,10 @@ type Emoji interface {
|
|||
GetUseableEmojis(ctx context.Context) ([]*gtsmodel.Emoji, error)
|
||||
|
||||
// GetEmojis fetches all emojis with IDs less than 'maxID', up to a maximum of 'limit' emojis.
|
||||
GetEmojis(ctx context.Context, maxID string, limit int) ([]*gtsmodel.Emoji, error)
|
||||
GetEmojis(ctx context.Context, page *paging.Page) ([]*gtsmodel.Emoji, error)
|
||||
|
||||
// GetRemoteEmojis fetches all remote emojis with IDs less than 'maxID', up to a maximum of 'limit' emojis.
|
||||
GetRemoteEmojis(ctx context.Context, maxID string, limit int) ([]*gtsmodel.Emoji, error)
|
||||
GetRemoteEmojis(ctx context.Context, page *paging.Page) ([]*gtsmodel.Emoji, error)
|
||||
|
||||
// GetCachedEmojisOlderThan fetches all cached remote emojis with 'updated_at' greater than 'olderThan', up to a maximum of 'limit' emojis.
|
||||
GetCachedEmojisOlderThan(ctx context.Context, olderThan time.Time, limit int) ([]*gtsmodel.Emoji, error)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||
)
|
||||
|
||||
// Media contains functions related to creating/getting/removing media attachments.
|
||||
|
|
@ -42,10 +43,10 @@ type Media interface {
|
|||
DeleteAttachment(ctx context.Context, id string) error
|
||||
|
||||
// GetAttachments fetches media attachments up to a given max ID, and at most limit.
|
||||
GetAttachments(ctx context.Context, maxID string, limit int) ([]*gtsmodel.MediaAttachment, error)
|
||||
GetAttachments(ctx context.Context, page *paging.Page) ([]*gtsmodel.MediaAttachment, error)
|
||||
|
||||
// GetRemoteAttachments fetches media attachments with a non-empty domain, up to a given max ID, and at most limit.
|
||||
GetRemoteAttachments(ctx context.Context, maxID string, limit int) ([]*gtsmodel.MediaAttachment, error)
|
||||
GetRemoteAttachments(ctx context.Context, page *paging.Page) ([]*gtsmodel.MediaAttachment, error)
|
||||
|
||||
// GetCachedAttachmentsOlderThan gets limit n remote attachments (including avatars and headers) older than
|
||||
// the given time. These will be returned in order of attachment.created_at descending (i.e. newest to oldest).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue