summaryrefslogtreecommitdiff
path: root/internal/db/bundb/status.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb/status.go')
-rw-r--r--internal/db/bundb/status.go26
1 files changed, 7 insertions, 19 deletions
diff --git a/internal/db/bundb/status.go b/internal/db/bundb/status.go
index 0fef01736..c34074dd6 100644
--- a/internal/db/bundb/status.go
+++ b/internal/db/bundb/status.go
@@ -43,7 +43,6 @@ func (s *statusDB) newStatusQ(status interface{}) *bun.SelectQuery {
return s.db.
NewSelect().
Model(status).
- Relation("Tags").
Relation("CreatedWithApplication")
}
@@ -440,24 +439,13 @@ func (s *statusDB) DeleteStatusByID(ctx context.Context, id string) error {
func (s *statusDB) GetStatusesUsingEmoji(ctx context.Context, emojiID string) ([]*gtsmodel.Status, error) {
var statusIDs []string
- // Create SELECT status query.
- q := s.db.NewSelect().
- Table("statuses").
- Column("id")
-
- // Append a WHERE LIKE clause to the query
- // that checks the `emoji` column for any
- // text containing this specific emoji ID.
- //
- // The reason we do this instead of doing a
- // `WHERE ? IN (emojis)` is that the latter
- // ends up being much MUCH slower, and the
- // database stores this ID-array-column as
- // text anyways, allowing a simple LIKE query.
- q = whereLike(q, "emojis", emojiID)
-
- // Execute the query, scanning destination into statusIDs.
- if _, err := q.Exec(ctx, &statusIDs); err != nil {
+ // SELECT all statuses using this emoji,
+ // using a relational table for improved perf.
+ if _, err := s.db.NewSelect().
+ Table("status_to_emojis").
+ Column("status_id").
+ Where("? = ?", bun.Ident("emoji_id"), emojiID).
+ Exec(ctx, &statusIDs); err != nil {
return nil, s.db.ProcessError(err)
}