mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-26 01:33:31 -06:00
[bugfix] fix slow accounts / statuses using emojis lookups (#2056)
* update DeleteEmoji to use faster relational tables for status / account finding
Signed-off-by: kim <grufwub@gmail.com>
* update Get{Accounts,Statuses}UsingEmoji() to also use relational tables
Signed-off-by: kim <grufwub@gmail.com>
* remove the now unneeded tags relation from newStatusQ()
Signed-off-by: kim <grufwub@gmail.com>
* fix table names
Signed-off-by: kim <grufwub@gmail.com>
* fix account and status selects using emojis
Signed-off-by: kim <grufwub@gmail.com>
---------
Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
24516b84c2
commit
2cee8f2dd8
3 changed files with 60 additions and 107 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue