Skip to content

Commit ebe803e

Browse files
JakobDevlunny
andauthored
Penultimate round of db.DefaultContext refactor (go-gitea#27414)
Part of go-gitea#27065 --------- Co-authored-by: Lunny Xiao <[email protected]>
1 parent 50166d1 commit ebe803e

File tree

136 files changed

+428
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+428
-421
lines changed

cmd/admin_auth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func runListAuth(c *cli.Context) error {
6262
return err
6363
}
6464

65-
authSources, err := auth_model.Sources()
65+
authSources, err := auth_model.Sources(ctx)
6666
if err != nil {
6767
return err
6868
}
@@ -100,7 +100,7 @@ func runDeleteAuth(c *cli.Context) error {
100100
return err
101101
}
102102

103-
source, err := auth_model.GetSourceByID(c.Int64("id"))
103+
source, err := auth_model.GetSourceByID(ctx, c.Int64("id"))
104104
if err != nil {
105105
return err
106106
}

cmd/admin_auth_ldap.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
type (
1818
authService struct {
1919
initDB func(ctx context.Context) error
20-
createAuthSource func(*auth.Source) error
21-
updateAuthSource func(*auth.Source) error
22-
getAuthSourceByID func(id int64) (*auth.Source, error)
20+
createAuthSource func(context.Context, *auth.Source) error
21+
updateAuthSource func(context.Context, *auth.Source) error
22+
getAuthSourceByID func(ctx context.Context, id int64) (*auth.Source, error)
2323
}
2424
)
2525

@@ -289,12 +289,12 @@ func findLdapSecurityProtocolByName(name string) (ldap.SecurityProtocol, bool) {
289289

290290
// getAuthSource gets the login source by its id defined in the command line flags.
291291
// It returns an error if the id is not set, does not match any source or if the source is not of expected type.
292-
func (a *authService) getAuthSource(c *cli.Context, authType auth.Type) (*auth.Source, error) {
292+
func (a *authService) getAuthSource(ctx context.Context, c *cli.Context, authType auth.Type) (*auth.Source, error) {
293293
if err := argsSet(c, "id"); err != nil {
294294
return nil, err
295295
}
296296

297-
authSource, err := a.getAuthSourceByID(c.Int64("id"))
297+
authSource, err := a.getAuthSourceByID(ctx, c.Int64("id"))
298298
if err != nil {
299299
return nil, err
300300
}
@@ -332,7 +332,7 @@ func (a *authService) addLdapBindDn(c *cli.Context) error {
332332
return err
333333
}
334334

335-
return a.createAuthSource(authSource)
335+
return a.createAuthSource(ctx, authSource)
336336
}
337337

338338
// updateLdapBindDn updates a new LDAP via Bind DN authentication source.
@@ -344,7 +344,7 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
344344
return err
345345
}
346346

347-
authSource, err := a.getAuthSource(c, auth.LDAP)
347+
authSource, err := a.getAuthSource(ctx, c, auth.LDAP)
348348
if err != nil {
349349
return err
350350
}
@@ -354,7 +354,7 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
354354
return err
355355
}
356356

357-
return a.updateAuthSource(authSource)
357+
return a.updateAuthSource(ctx, authSource)
358358
}
359359

360360
// addLdapSimpleAuth adds a new LDAP (simple auth) authentication source.
@@ -383,7 +383,7 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
383383
return err
384384
}
385385

386-
return a.createAuthSource(authSource)
386+
return a.createAuthSource(ctx, authSource)
387387
}
388388

389389
// updateLdapBindDn updates a new LDAP (simple auth) authentication source.
@@ -395,7 +395,7 @@ func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
395395
return err
396396
}
397397

398-
authSource, err := a.getAuthSource(c, auth.DLDAP)
398+
authSource, err := a.getAuthSource(ctx, c, auth.DLDAP)
399399
if err != nil {
400400
return err
401401
}
@@ -405,5 +405,5 @@ func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
405405
return err
406406
}
407407

408-
return a.updateAuthSource(authSource)
408+
return a.updateAuthSource(ctx, authSource)
409409
}

cmd/admin_auth_ldap_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ func TestAddLdapBindDn(t *testing.T) {
210210
initDB: func(context.Context) error {
211211
return nil
212212
},
213-
createAuthSource: func(authSource *auth.Source) error {
213+
createAuthSource: func(ctx context.Context, authSource *auth.Source) error {
214214
createdAuthSource = authSource
215215
return nil
216216
},
217-
updateAuthSource: func(authSource *auth.Source) error {
217+
updateAuthSource: func(ctx context.Context, authSource *auth.Source) error {
218218
assert.FailNow(t, "case %d: should not call updateAuthSource", n)
219219
return nil
220220
},
221-
getAuthSourceByID: func(id int64) (*auth.Source, error) {
221+
getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) {
222222
assert.FailNow(t, "case %d: should not call getAuthSourceByID", n)
223223
return nil, nil
224224
},
@@ -441,15 +441,15 @@ func TestAddLdapSimpleAuth(t *testing.T) {
441441
initDB: func(context.Context) error {
442442
return nil
443443
},
444-
createAuthSource: func(authSource *auth.Source) error {
444+
createAuthSource: func(ctx context.Context, authSource *auth.Source) error {
445445
createdAuthSource = authSource
446446
return nil
447447
},
448-
updateAuthSource: func(authSource *auth.Source) error {
448+
updateAuthSource: func(ctx context.Context, authSource *auth.Source) error {
449449
assert.FailNow(t, "case %d: should not call updateAuthSource", n)
450450
return nil
451451
},
452-
getAuthSourceByID: func(id int64) (*auth.Source, error) {
452+
getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) {
453453
assert.FailNow(t, "case %d: should not call getAuthSourceByID", n)
454454
return nil, nil
455455
},
@@ -896,15 +896,15 @@ func TestUpdateLdapBindDn(t *testing.T) {
896896
initDB: func(context.Context) error {
897897
return nil
898898
},
899-
createAuthSource: func(authSource *auth.Source) error {
899+
createAuthSource: func(ctx context.Context, authSource *auth.Source) error {
900900
assert.FailNow(t, "case %d: should not call createAuthSource", n)
901901
return nil
902902
},
903-
updateAuthSource: func(authSource *auth.Source) error {
903+
updateAuthSource: func(ctx context.Context, authSource *auth.Source) error {
904904
updatedAuthSource = authSource
905905
return nil
906906
},
907-
getAuthSourceByID: func(id int64) (*auth.Source, error) {
907+
getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) {
908908
if c.id != 0 {
909909
assert.Equal(t, c.id, id, "case %d: wrong id", n)
910910
}
@@ -1286,15 +1286,15 @@ func TestUpdateLdapSimpleAuth(t *testing.T) {
12861286
initDB: func(context.Context) error {
12871287
return nil
12881288
},
1289-
createAuthSource: func(authSource *auth.Source) error {
1289+
createAuthSource: func(ctx context.Context, authSource *auth.Source) error {
12901290
assert.FailNow(t, "case %d: should not call createAuthSource", n)
12911291
return nil
12921292
},
1293-
updateAuthSource: func(authSource *auth.Source) error {
1293+
updateAuthSource: func(ctx context.Context, authSource *auth.Source) error {
12941294
updatedAuthSource = authSource
12951295
return nil
12961296
},
1297-
getAuthSourceByID: func(id int64) (*auth.Source, error) {
1297+
getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) {
12981298
if c.id != 0 {
12991299
assert.Equal(t, c.id, id, "case %d: wrong id", n)
13001300
}

cmd/admin_auth_oauth.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func runAddOauth(c *cli.Context) error {
183183
}
184184
}
185185

186-
return auth_model.CreateSource(&auth_model.Source{
186+
return auth_model.CreateSource(ctx, &auth_model.Source{
187187
Type: auth_model.OAuth2,
188188
Name: c.String("name"),
189189
IsActive: true,
@@ -203,7 +203,7 @@ func runUpdateOauth(c *cli.Context) error {
203203
return err
204204
}
205205

206-
source, err := auth_model.GetSourceByID(c.Int64("id"))
206+
source, err := auth_model.GetSourceByID(ctx, c.Int64("id"))
207207
if err != nil {
208208
return err
209209
}
@@ -294,5 +294,5 @@ func runUpdateOauth(c *cli.Context) error {
294294
oAuth2Config.CustomURLMapping = customURLMapping
295295
source.Cfg = oAuth2Config
296296

297-
return auth_model.UpdateSource(source)
297+
return auth_model.UpdateSource(ctx, source)
298298
}

cmd/admin_auth_stmp.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func runAddSMTP(c *cli.Context) error {
156156
smtpConfig.Auth = "PLAIN"
157157
}
158158

159-
return auth_model.CreateSource(&auth_model.Source{
159+
return auth_model.CreateSource(ctx, &auth_model.Source{
160160
Type: auth_model.SMTP,
161161
Name: c.String("name"),
162162
IsActive: active,
@@ -176,7 +176,7 @@ func runUpdateSMTP(c *cli.Context) error {
176176
return err
177177
}
178178

179-
source, err := auth_model.GetSourceByID(c.Int64("id"))
179+
source, err := auth_model.GetSourceByID(ctx, c.Int64("id"))
180180
if err != nil {
181181
return err
182182
}
@@ -197,5 +197,5 @@ func runUpdateSMTP(c *cli.Context) error {
197197

198198
source.Cfg = smtpConfig
199199

200-
return auth_model.UpdateSource(source)
200+
return auth_model.UpdateSource(ctx, source)
201201
}

models/actions/run_job_list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (jobs ActionJobList) LoadRuns(ctx context.Context, withRepo bool) error {
4242
for _, r := range runs {
4343
runsList = append(runsList, r)
4444
}
45-
return runsList.LoadRepos()
45+
return runsList.LoadRepos(ctx)
4646
}
4747
return nil
4848
}

models/actions/run_list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ func (runs RunList) LoadTriggerUser(ctx context.Context) error {
5252
return nil
5353
}
5454

55-
func (runs RunList) LoadRepos() error {
55+
func (runs RunList) LoadRepos(ctx context.Context) error {
5656
repoIDs := runs.GetRepoIDs()
57-
repos, err := repo_model.GetRepositoriesMapByIDs(repoIDs)
57+
repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs)
5858
if err != nil {
5959
return err
6060
}

models/actions/schedule_list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ func (schedules ScheduleList) LoadTriggerUser(ctx context.Context) error {
4949
return nil
5050
}
5151

52-
func (schedules ScheduleList) LoadRepos() error {
52+
func (schedules ScheduleList) LoadRepos(ctx context.Context) error {
5353
repoIDs := schedules.GetRepoIDs()
54-
repos, err := repo_model.GetRepositoriesMapByIDs(repoIDs)
54+
repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs)
5555
if err != nil {
5656
return err
5757
}

models/actions/schedule_spec_list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ func (specs SpecList) GetRepoIDs() []int64 {
5353
return ids.Values()
5454
}
5555

56-
func (specs SpecList) LoadRepos() error {
56+
func (specs SpecList) LoadRepos(ctx context.Context) error {
5757
repoIDs := specs.GetRepoIDs()
58-
repos, err := repo_model.GetRepositoriesMapByIDs(repoIDs)
58+
repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs)
5959
if err != nil {
6060
return err
6161
}

models/activities/statistic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func GetStatistic(ctx context.Context) (stats Statistic) {
102102
stats.Counter.Follow, _ = e.Count(new(user_model.Follow))
103103
stats.Counter.Mirror, _ = e.Count(new(repo_model.Mirror))
104104
stats.Counter.Release, _ = e.Count(new(repo_model.Release))
105-
stats.Counter.AuthSource = auth.CountSources()
105+
stats.Counter.AuthSource = auth.CountSources(ctx)
106106
stats.Counter.Webhook, _ = e.Count(new(webhook.Webhook))
107107
stats.Counter.Milestone, _ = e.Count(new(issues_model.Milestone))
108108
stats.Counter.Label, _ = e.Count(new(issues_model.Label))

0 commit comments

Comments
 (0)