mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
Database updates (#144)
* start moving some database stuff around * continue moving db stuff around * more fiddling * more updates * and some more * and yet more * i broke SOMETHING but what, it's a mystery * tidy up * vendor ttlcache * use ttlcache * fix up some tests * rename some stuff * little reminder * some more updates
This commit is contained in:
@ -90,7 +90,7 @@ func (p *processor) SearchGet(authed *oauth.Auth, searchQuery *apimodel.SearchQu
|
||||
*/
|
||||
for _, foundAccount := range foundAccounts {
|
||||
// make sure there's no block in either direction between the account and the requester
|
||||
if blocked, err := p.db.Blocked(authed.Account.ID, foundAccount.ID); err == nil && !blocked {
|
||||
if blocked, err := p.db.IsBlocked(authed.Account.ID, foundAccount.ID, true); err == nil && !blocked {
|
||||
// all good, convert it and add it to the results
|
||||
if acctMasto, err := p.tc.AccountToMastoPublic(foundAccount); err == nil && acctMasto != nil {
|
||||
results.Accounts = append(results.Accounts, *acctMasto)
|
||||
@ -99,11 +99,6 @@ func (p *processor) SearchGet(authed *oauth.Auth, searchQuery *apimodel.SearchQu
|
||||
}
|
||||
|
||||
for _, foundStatus := range foundStatuses {
|
||||
statusOwner := >smodel.Account{}
|
||||
if err := p.db.GetByID(foundStatus.AccountID, statusOwner); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if visible, err := p.filter.StatusVisible(foundStatus, authed.Account); !visible || err != nil {
|
||||
continue
|
||||
}
|
||||
@ -126,12 +121,9 @@ func (p *processor) searchStatusByURI(authed *oauth.Auth, uri *url.URL, resolve
|
||||
"resolve": resolve,
|
||||
})
|
||||
|
||||
maybeStatus := >smodel.Status{}
|
||||
if err := p.db.GetWhere([]db.Where{{Key: "uri", Value: uri.String(), CaseInsensitive: true}}, maybeStatus); err == nil {
|
||||
// we have it and it's a status
|
||||
if maybeStatus, err := p.db.GetStatusByURI(uri.String()); err == nil {
|
||||
return maybeStatus, nil
|
||||
} else if err := p.db.GetWhere([]db.Where{{Key: "url", Value: uri.String(), CaseInsensitive: true}}, maybeStatus); err == nil {
|
||||
// we have it and it's a status
|
||||
} else if maybeStatus, err := p.db.GetStatusByURL(uri.String()); err == nil {
|
||||
return maybeStatus, nil
|
||||
}
|
||||
|
||||
@ -150,14 +142,12 @@ func (p *processor) searchStatusByURI(authed *oauth.Auth, uri *url.URL, resolve
|
||||
}
|
||||
|
||||
func (p *processor) searchAccountByURI(authed *oauth.Auth, uri *url.URL, resolve bool) (*gtsmodel.Account, error) {
|
||||
maybeAccount := >smodel.Account{}
|
||||
if err := p.db.GetWhere([]db.Where{{Key: "uri", Value: uri.String(), CaseInsensitive: true}}, maybeAccount); err == nil {
|
||||
// we have it and it's an account
|
||||
if maybeAccount, err := p.db.GetAccountByURI(uri.String()); err == nil {
|
||||
return maybeAccount, nil
|
||||
} else if err = p.db.GetWhere([]db.Where{{Key: "url", Value: uri.String(), CaseInsensitive: true}}, maybeAccount); err == nil {
|
||||
// we have it and it's an account
|
||||
} else if maybeAccount, err := p.db.GetAccountByURL(uri.String()); err == nil {
|
||||
return maybeAccount, nil
|
||||
}
|
||||
|
||||
if resolve {
|
||||
// we don't have it locally so try and dereference it
|
||||
account, _, err := p.federator.GetRemoteAccount(authed.Account.Username, uri, true)
|
||||
@ -179,7 +169,8 @@ func (p *processor) searchAccountByMention(authed *oauth.Auth, mention string, r
|
||||
// if it's a local account we can skip a whole bunch of stuff
|
||||
maybeAcct := >smodel.Account{}
|
||||
if domain == p.config.Host {
|
||||
if err = p.db.GetLocalAccountByUsername(username, maybeAcct); err != nil {
|
||||
maybeAcct, err = p.db.GetLocalAccountByUsername(username)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("searchAccountByMention: error getting local account by username: %s", err)
|
||||
}
|
||||
return maybeAcct, nil
|
||||
@ -196,7 +187,7 @@ func (p *processor) searchAccountByMention(authed *oauth.Auth, mention string, r
|
||||
return maybeAcct, nil
|
||||
}
|
||||
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
if err != db.ErrNoEntries {
|
||||
// if it's not errNoEntries there's been a real database error so bail at this point
|
||||
return nil, fmt.Errorf("searchAccountByMention: database error: %s", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user