diff options
author | 2022-10-08 13:50:48 +0200 | |
---|---|---|
committer | 2022-10-08 13:50:48 +0200 | |
commit | aa07750bdb4dacdb1be39d765114915bba3fc29f (patch) | |
tree | 30e9e5052f607f8c8e4f7d518559df8706275e0f /internal/db/bundb/notification.go | |
parent | [performance] cache domains after max retries in transport (#884) (diff) | |
download | gotosocial-aa07750bdb4dacdb1be39d765114915bba3fc29f.tar.xz |
[chore] Standardize database queries, use `bun.Ident()` properly (#886)
* use bun.Ident for user queries
* use bun.Ident for account queries
* use bun.Ident for media queries
* add DeleteAccount func
* remove CaseInsensitive in Where+use Ident ipv Safe
* update admin db
* update domain, use ident
* update emoji, use ident
* update instance queries, use bun.Ident
* fix media
* update mentions, use bun ident
* update relationship + tests
* use tableexpr
* add test follows to bun db test suite
* update notifications
* updatebyprimarykey => updatebyid
* fix session
* prefer explicit ID to pk
* fix little fucky wucky
* remove workaround
* use proper db func for attachment selection
* update status db
* add m2m entries in test rig
* fix up timeline
* go fmt
* fix status put issue
* update GetAccountStatuses
Diffstat (limited to 'internal/db/bundb/notification.go')
-rw-r--r-- | internal/db/bundb/notification.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/internal/db/bundb/notification.go b/internal/db/bundb/notification.go index 32523ca24..69e3cf39f 100644 --- a/internal/db/bundb/notification.go +++ b/internal/db/bundb/notification.go @@ -25,6 +25,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/log" + "github.com/uptrace/bun" ) type notificationDB struct { @@ -44,7 +45,7 @@ func (n *notificationDB) GetNotification(ctx context.Context, id string) (*gtsmo Relation("OriginAccount"). Relation("TargetAccount"). Relation("Status"). - WherePK() + Where("? = ?", bun.Ident("notification.id"), id) if err := q.Scan(ctx); err != nil { return nil, n.conn.ProcessError(err) @@ -67,24 +68,24 @@ func (n *notificationDB) GetNotifications(ctx context.Context, accountID string, q := n.conn. NewSelect(). - Table("notifications"). - Column("id") + TableExpr("? AS ?", bun.Ident("notifications"), bun.Ident("notification")). + Column("notification.id") if maxID != "" { - q = q.Where("id < ?", maxID) + q = q.Where("? < ?", bun.Ident("notification.id"), maxID) } if sinceID != "" { - q = q.Where("id > ?", sinceID) + q = q.Where("? > ?", bun.Ident("notification.id"), sinceID) } for _, excludeType := range excludeTypes { - q = q.Where("notification_type != ?", excludeType) + q = q.Where("? != ?", bun.Ident("notification.notification_type"), excludeType) } q = q. - Where("target_account_id = ?", accountID). - Order("id DESC") + Where("? = ?", bun.Ident("notification.target_account_id"), accountID). + Order("notification.id DESC") if limit != 0 { q = q.Limit(limit) @@ -116,13 +117,12 @@ func (n *notificationDB) GetNotifications(ctx context.Context, accountID string, func (n *notificationDB) ClearNotifications(ctx context.Context, accountID string) db.Error { if _, err := n.conn. NewDelete(). - Table("notifications"). - Where("target_account_id = ?", accountID). + TableExpr("? AS ?", bun.Ident("notifications"), bun.Ident("notification")). + Where("? = ?", bun.Ident("notification.target_account_id"), accountID). Exec(ctx); err != nil { return n.conn.ProcessError(err) } n.cache.Clear() - return nil } |