1
0
Fork 0
forked from forgejo/forgejo

Replace more db.DefaultContext (#27628)

Target #27065
This commit is contained in:
Lunny Xiao 2023-10-15 23:46:06 +08:00 committed by GitHub
parent 7480aacdad
commit cddf245c12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 99 additions and 85 deletions

View file

@ -716,7 +716,7 @@ func FindUserCodeAccessibleOwnerRepoIDs(ctx context.Context, ownerID int64, user
}
// GetUserRepositories returns a list of repositories of given user.
func GetUserRepositories(opts *SearchRepoOptions) (RepositoryList, int64, error) {
func GetUserRepositories(ctx context.Context, opts *SearchRepoOptions) (RepositoryList, int64, error) {
if len(opts.OrderBy) == 0 {
opts.OrderBy = "updated_unix DESC"
}
@ -734,7 +734,7 @@ func GetUserRepositories(opts *SearchRepoOptions) (RepositoryList, int64, error)
cond = cond.And(builder.In("lower_name", opts.LowerNames))
}
sess := db.GetEngine(db.DefaultContext)
sess := db.GetEngine(ctx)
count, err := sess.Where(cond).Count(new(Repository))
if err != nil {

View file

@ -107,12 +107,12 @@ func watchRepoMode(ctx context.Context, watch Watch, mode WatchMode) (err error)
}
// WatchRepoMode watch repository in specific mode.
func WatchRepoMode(userID, repoID int64, mode WatchMode) (err error) {
func WatchRepoMode(ctx context.Context, userID, repoID int64, mode WatchMode) (err error) {
var watch Watch
if watch, err = GetWatch(db.DefaultContext, userID, repoID); err != nil {
if watch, err = GetWatch(ctx, userID, repoID); err != nil {
return err
}
return watchRepoMode(db.DefaultContext, watch, mode)
return watchRepoMode(ctx, watch, mode)
}
// WatchRepo watch or unwatch repository.

View file

@ -122,18 +122,18 @@ func TestWatchRepoMode(t *testing.T) {
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 0)
assert.NoError(t, repo_model.WatchRepoMode(12, 1, repo_model.WatchModeAuto))
assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeAuto))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1, Mode: repo_model.WatchModeAuto}, 1)
assert.NoError(t, repo_model.WatchRepoMode(12, 1, repo_model.WatchModeNormal))
assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeNormal))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1, Mode: repo_model.WatchModeNormal}, 1)
assert.NoError(t, repo_model.WatchRepoMode(12, 1, repo_model.WatchModeDont))
assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeDont))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1, Mode: repo_model.WatchModeDont}, 1)
assert.NoError(t, repo_model.WatchRepoMode(12, 1, repo_model.WatchModeNone))
assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeNone))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 0)
}