Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[performance] Use caches instead of relations when selecting notifs #1072

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions internal/db/bundb/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ func (n *notificationDB) GetNotification(ctx context.Context, id string) (*gtsmo

q := n.conn.NewSelect().
Model(&notif).
Relation("OriginAccount").
Relation("TargetAccount").
Relation("Status").
Where("? = ?", bun.Ident("notification.id"), id)
if err := q.Scan(ctx); err != nil {
return nil, n.conn.ProcessError(err)
Expand Down
3 changes: 0 additions & 3 deletions internal/db/bundb/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ func (suite *NotificationTestSuite) TestGetNotificationsWithoutSpam() {
suite.NotNil(notifications)
for _, n := range notifications {
suite.Equal(testAccount.ID, n.TargetAccountID)
suite.NotNil(n.OriginAccount)
suite.NotNil(n.TargetAccount)
suite.NotNil(n.Status)
}
}

Expand Down
10 changes: 5 additions & 5 deletions internal/gtsmodel/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import "time"
type Notification struct {
ID string `validate:"required,ulid" bun:"type:CHAR(26),pk,nullzero,notnull,unique"` // id of this item in the database
CreatedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item created
UpdatedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item last updated // when was item created
UpdatedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item last updated
NotificationType NotificationType `validate:"oneof=follow follow_request mention reblog favourite poll status" bun:",nullzero,notnull"` // Type of this notification
TargetAccountID string `validate:"ulid" bun:"type:CHAR(26),nullzero,notnull"` // Which account does this notification target (ie., who will receive the notification?)
TargetAccount *Account `validate:"-" bun:"rel:belongs-to"` // Which account performed the action that created this notification?
TargetAccountID string `validate:"ulid" bun:"type:CHAR(26),nullzero,notnull"` // ID of the account targeted by the notification (ie., who will receive the notification?)
TargetAccount *Account `validate:"-" bun:"-"` // Account corresponding to TargetAccountID. Can be nil, always check first + select using ID if necessary.
OriginAccountID string `validate:"ulid" bun:"type:CHAR(26),nullzero,notnull"` // ID of the account that performed the action that created the notification.
OriginAccount *Account `validate:"-" bun:"rel:belongs-to"` // Account corresponding to originAccountID
OriginAccount *Account `validate:"-" bun:"-"` // Account corresponding to OriginAccountID. Can be nil, always check first + select using ID if necessary.
StatusID string `validate:"required_if=NotificationType mention,required_if=NotificationType reblog,required_if=NotificationType favourite,required_if=NotificationType status,omitempty,ulid" bun:"type:CHAR(26),nullzero"` // If the notification pertains to a status, what is the database ID of that status?
Status *Status `validate:"-" bun:"rel:belongs-to"` // Status corresponding to statusID
Status *Status `validate:"-" bun:"-"` // Status corresponding to StatusID. Can be nil, always check first + select using ID if necessary.
Read *bool `validate:"-" bun:",nullzero,notnull,default:false"` // Notification has been seen/read
}

Expand Down