mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 10:12:26 -05: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
|
|
@ -468,24 +468,13 @@ func (a *accountDB) GetAccountCustomCSSByUsername(ctx context.Context, username
|
|||
func (a *accountDB) GetAccountsUsingEmoji(ctx context.Context, emojiID string) ([]*gtsmodel.Account, error) {
|
||||
var accountIDs []string
|
||||
|
||||
// Create SELECT account query.
|
||||
q := a.db.NewSelect().
|
||||
Table("accounts").
|
||||
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 accountIDs.
|
||||
if _, err := q.Exec(ctx, &accountIDs); err != nil {
|
||||
// SELECT all accounts using this emoji,
|
||||
// using a relational table for improved perf.
|
||||
if _, err := a.db.NewSelect().
|
||||
Table("account_to_emojis").
|
||||
Column("account_id").
|
||||
Where("? = ?", bun.Ident("emoji_id"), emojiID).
|
||||
Exec(ctx, &accountIDs); err != nil {
|
||||
return nil, a.db.ProcessError(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue