summaryrefslogtreecommitdiff
path: root/internal/db/bundb
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-01-31 13:31:53 +0000
committerLibravatar GitHub <noreply@github.com>2024-01-31 13:31:53 +0000
commitc9452f32f38b9ac1fb96a834202fd3e2f25897a1 (patch)
treed61ed47e1c8ce010791ffa309da963f0304c92b8 /internal/db/bundb
parent[bugfix] parent status replied to status not dereferenced sometimes (#2587) (diff)
downloadgotosocial-c9452f32f38b9ac1fb96a834202fd3e2f25897a1.tar.xz
[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
Diffstat (limited to 'internal/db/bundb')
-rw-r--r--internal/db/bundb/emoji.go15
-rw-r--r--internal/db/bundb/media.go11
2 files changed, 20 insertions, 6 deletions
diff --git a/internal/db/bundb/emoji.go b/internal/db/bundb/emoji.go
index d1cb9dfbd..608cb6417 100644
--- a/internal/db/bundb/emoji.go
+++ b/internal/db/bundb/emoji.go
@@ -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").
diff --git a/internal/db/bundb/media.go b/internal/db/bundb/media.go
index ce3c90083..ced38a588 100644
--- a/internal/db/bundb/media.go
+++ b/internal/db/bundb/media.go
@@ -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().