[performance] Database optimizations (#419)

* 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
This commit is contained in:
tobi 2022-03-07 11:33:18 +01:00 committed by GitHub
commit 8de928b5e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 427 additions and 8 deletions

View file

@ -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)