mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-16 21:47:34 -06:00
[performance] Speed up some of the slower db queries (#523)
* remove unnecessary LOWER() db calls * warn during slow db queries * use bundb built-in exists function * add db block test * update account block query * add domain block db test * optimize domain block query * fix implementing wrong test * exclude most columns when checking block * go fmt * remote more unnecessary use of LOWER()
This commit is contained in:
parent
faae2505c0
commit
a5852fd7e4
13 changed files with 151 additions and 29 deletions
|
|
@ -52,14 +52,25 @@ func (r *relationshipDB) IsBlocked(ctx context.Context, account1 string, account
|
|||
q := r.conn.
|
||||
NewSelect().
|
||||
Model(>smodel.Block{}).
|
||||
Where("account_id = ?", account1).
|
||||
Where("target_account_id = ?", account2).
|
||||
ExcludeColumn("id", "created_at", "updated_at", "uri").
|
||||
Limit(1)
|
||||
|
||||
if eitherDirection {
|
||||
q = q.
|
||||
WhereOr("target_account_id = ?", account1).
|
||||
Where("account_id = ?", account2)
|
||||
WhereGroup(" OR ", func(inner *bun.SelectQuery) *bun.SelectQuery {
|
||||
return inner.
|
||||
Where("account_id = ?", account1).
|
||||
Where("target_account_id = ?", account2)
|
||||
}).
|
||||
WhereGroup(" OR ", func(inner *bun.SelectQuery) *bun.SelectQuery {
|
||||
return inner.
|
||||
Where("account_id = ?", account2).
|
||||
Where("target_account_id = ?", account1)
|
||||
})
|
||||
} else {
|
||||
q = q.
|
||||
Where("account_id = ?", account1).
|
||||
Where("target_account_id = ?", account2)
|
||||
}
|
||||
|
||||
return r.conn.Exists(ctx, q)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue