don't repeat regex parsing

This commit is contained in:
tsmethurst 2022-06-02 16:38:30 +02:00
parent d2c512575c
commit 2edc5c702a

View file

@ -160,16 +160,12 @@ func (p *processor) searchAccountByURI(ctx context.Context, authed *oauth.Auth,
return nil, nil return nil, nil
} }
func (p *processor) searchAccountByMention(ctx context.Context, authed *oauth.Auth, mention string, resolve bool) (*gtsmodel.Account, error) { func (p *processor) searchAccountByMention(ctx context.Context, authed *oauth.Auth, username string, domain string, resolve bool) (*gtsmodel.Account, error) {
// query is for a remote account maybeAcct := &gtsmodel.Account{}
username, host, err := util.ExtractNamestringParts(mention) var err error
if err != nil {
return nil, fmt.Errorf("searchAccountByMention: error extracting mention parts: %s", err)
}
// if it's a local account we can skip a whole bunch of stuff // if it's a local account we can skip a whole bunch of stuff
maybeAcct := &gtsmodel.Account{} if domain == config.GetHost() {
if host == config.GetHost() {
maybeAcct, err = p.db.GetLocalAccountByUsername(ctx, username) maybeAcct, err = p.db.GetLocalAccountByUsername(ctx, username)
if err != nil { if err != nil {
return nil, fmt.Errorf("searchAccountByMention: error getting local account by username: %s", err) return nil, fmt.Errorf("searchAccountByMention: error getting local account by username: %s", err)
@ -180,7 +176,7 @@ func (p *processor) searchAccountByMention(ctx context.Context, authed *oauth.Au
// it's not a local account so first we'll check if it's in the database already... // it's not a local account so first we'll check if it's in the database already...
where := []db.Where{ where := []db.Where{
{Key: "username", Value: username, CaseInsensitive: true}, {Key: "username", Value: username, CaseInsensitive: true},
{Key: "domain", Value: host, CaseInsensitive: true}, {Key: "domain", Value: domain, CaseInsensitive: true},
} }
err = p.db.GetWhere(ctx, where, maybeAcct) err = p.db.GetWhere(ctx, where, maybeAcct)
if err == nil { if err == nil {
@ -198,7 +194,7 @@ func (p *processor) searchAccountByMention(ctx context.Context, authed *oauth.Au
maybeAcct, err = p.federator.GetRemoteAccount(ctx, dereferencing.GetRemoteAccountParams{ maybeAcct, err = p.federator.GetRemoteAccount(ctx, dereferencing.GetRemoteAccountParams{
RequestingUsername: authed.Account.Username, RequestingUsername: authed.Account.Username,
RemoteAccountUsername: username, RemoteAccountUsername: username,
RemoteAccountHost: host, RemoteAccountHost: domain,
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf("searchAccountByMention: error getting remote account: %s", err) return nil, fmt.Errorf("searchAccountByMention: error getting remote account: %s", err)