summaryrefslogtreecommitdiff
path: root/internal/db/bundb/account.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb/account.go')
-rw-r--r--internal/db/bundb/account.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go
index 17339732e..179db6bb3 100644
--- a/internal/db/bundb/account.go
+++ b/internal/db/bundb/account.go
@@ -56,6 +56,27 @@ func (a *accountDB) GetAccountByID(ctx context.Context, id string) (*gtsmodel.Ac
)
}
+func (a *accountDB) GetAccountsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.Account, error) {
+ accounts := make([]*gtsmodel.Account, 0, len(ids))
+
+ for _, id := range ids {
+ // Attempt to fetch account from DB.
+ account, err := a.GetAccountByID(
+ gtscontext.SetBarebones(ctx),
+ id,
+ )
+ if err != nil {
+ log.Errorf(ctx, "error getting account %q: %v", id, err)
+ continue
+ }
+
+ // Append account to return slice.
+ accounts = append(accounts, account)
+ }
+
+ return accounts, nil
+}
+
func (a *accountDB) GetAccountByURI(ctx context.Context, uri string) (*gtsmodel.Account, db.Error) {
return a.getAccount(
ctx,
@@ -444,6 +465,34 @@ func (a *accountDB) GetAccountCustomCSSByUsername(ctx context.Context, username
return account.CustomCSS, nil
}
+func (a *accountDB) GetAccountsUsingEmoji(ctx context.Context, emojiID string) ([]*gtsmodel.Account, error) {
+ var accountIDs []string
+
+ // Create SELECT account query.
+ q := a.conn.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 {
+ return nil, a.conn.ProcessError(err)
+ }
+
+ // Convert account IDs into account objects.
+ return a.GetAccountsByIDs(ctx, accountIDs)
+}
+
func (a *accountDB) GetAccountFaves(ctx context.Context, accountID string) ([]*gtsmodel.StatusFave, db.Error) {
faves := new([]*gtsmodel.StatusFave)