summaryrefslogtreecommitdiff
path: root/internal/db/bundb/notification.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-03-07 11:33:18 +0100
committerLibravatar GitHub <noreply@github.com>2022-03-07 11:33:18 +0100
commit8de928b5e9441d3968e5f79860f4de08d52f24ed (patch)
treec5a4188e61294d59e73e0e3a1f0c684c7be112fd /internal/db/bundb/notification.go
parent[feature] Clean up/uncache remote media (#407) (diff)
downloadgotosocial-8de928b5e9441d3968e5f79860f4de08d52f24ed.tar.xz
[performance] Database optimizations (#419)v0.2.1
* create first index on notifications * tidy up + add tests * log queries for trace, ops for debug * index commonly used fields * rearrange query * add a few more indexes * remove schema-breaking index (add this back in later) * re-add cleanup query index
Diffstat (limited to 'internal/db/bundb/notification.go')
-rw-r--r--internal/db/bundb/notification.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/internal/db/bundb/notification.go b/internal/db/bundb/notification.go
index 35b7e32af..e030cc623 100644
--- a/internal/db/bundb/notification.go
+++ b/internal/db/bundb/notification.go
@@ -66,9 +66,7 @@ func (n *notificationDB) GetNotifications(ctx context.Context, accountID string,
q := n.conn.
NewSelect().
Model(&notifications).
- Column("id").
- Where("target_account_id = ?", accountID).
- Order("id DESC")
+ Column("id")
if maxID != "" {
q = q.Where("id < ?", maxID)
@@ -78,6 +76,10 @@ func (n *notificationDB) GetNotifications(ctx context.Context, accountID string,
q = q.Where("id > ?", sinceID)
}
+ q = q.
+ Where("target_account_id = ?", accountID).
+ Order("id DESC")
+
if limit != 0 {
q = q.Limit(limit)
}
@@ -120,8 +122,7 @@ func (n *notificationDB) putNotificationCache(notif *gtsmodel.Notification) {
}
func (n *notificationDB) getNotificationDB(ctx context.Context, id string, dst *gtsmodel.Notification) error {
- q := n.newNotificationQ(dst).
- Where("notification.id = ?", id)
+ q := n.newNotificationQ(dst).WherePK()
if err := q.Scan(ctx); err != nil {
return n.conn.ProcessError(err)