summaryrefslogtreecommitdiff
path: root/internal/db/bundb/relationship.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-05-02 12:53:46 +0200
committerLibravatar GitHub <noreply@github.com>2022-05-02 11:53:46 +0100
commita5852fd7e43bf97ea7def9de20cd6d02d954094d (patch)
treed72b7fe9bf603786a5533e6b566a8412b2b8f634 /internal/db/bundb/relationship.go
parentAdd logging to the new generic worker package (#516) (diff)
downloadgotosocial-a5852fd7e43bf97ea7def9de20cd6d02d954094d.tar.xz
[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()
Diffstat (limited to 'internal/db/bundb/relationship.go')
-rw-r--r--internal/db/bundb/relationship.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/internal/db/bundb/relationship.go b/internal/db/bundb/relationship.go
index 369553205..e2e2c96b2 100644
--- a/internal/db/bundb/relationship.go
+++ b/internal/db/bundb/relationship.go
@@ -52,14 +52,25 @@ func (r *relationshipDB) IsBlocked(ctx context.Context, account1 string, account
q := r.conn.
NewSelect().
Model(&gtsmodel.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)