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

Fix bug with sqlite load read #26305

Merged
merged 13 commits into from
Aug 5, 2023
2 changes: 1 addition & 1 deletion models/activities/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ func GetUIDsAndNotificationCounts(since, until timeutil.TimeStamp) ([]UserIDCoun

// SetIssueReadBy sets issue to be read by given user.
func SetIssueReadBy(ctx context.Context, issueID, userID int64) error {
if err := issues_model.UpdateIssueUserByRead(userID, issueID); err != nil {
if err := issues_model.UpdateIssueUserByRead(ctx, userID, issueID); err != nil {
return err
}

Expand Down
15 changes: 15 additions & 0 deletions models/activities/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package activities_test

import (
"context"
"testing"

activities_model "code.gitea.io/gitea/models/activities"
Expand Down Expand Up @@ -109,3 +110,17 @@ func TestUpdateNotificationStatuses(t *testing.T) {
unittest.AssertExistsAndLoadBean(t,
&activities_model.Notification{ID: notfPinned.ID, Status: activities_model.NotificationStatusPinned})
}

func TestSetIssueReadBy(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
db.WithTx(db.DefaultContext, func(ctx context.Context) error {
assert.NoError(t, activities_model.SetIssueReadBy(ctx, issue.ID, user.ID))
return nil
})

cnt, err := activities_model.GetNotificationCount(db.DefaultContext, user, activities_model.NotificationStatusUnread)
assert.NoError(t, err)
assert.EqualValues(t, 0, cnt)
}
4 changes: 2 additions & 2 deletions models/issues/issue_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func NewIssueUsers(ctx context.Context, repo *repo_model.Repository, issue *Issu
}

// UpdateIssueUserByRead updates issue-user relation for reading.
func UpdateIssueUserByRead(uid, issueID int64) error {
_, err := db.GetEngine(db.DefaultContext).Exec("UPDATE `issue_user` SET is_read=? WHERE uid=? AND issue_id=?", true, uid, issueID)
func UpdateIssueUserByRead(ctx context.Context, uid, issueID int64) error {
_, err := db.GetEngine(ctx).Exec("UPDATE `issue_user` SET is_read=? WHERE uid=? AND issue_id=?", true, uid, issueID)
return err
}

Expand Down