1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

Reduce usage of db.DefaultContext (#27073)

Part of #27065

This reduces the usage of `db.DefaultContext`. I think I've got enough
files for the first PR. When this is merged, I will continue working on
this.

Considering how many files this PR affect, I hope it won't take to long
to merge, so I don't end up in the merge conflict hell.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
JakobDev
2023-09-14 19:09:32 +02:00
committed by GitHub
parent 0de09d3afc
commit 76659b1114
83 changed files with 339 additions and 324 deletions

View File

@@ -25,19 +25,19 @@ func (users UserList) GetUserIDs() []int64 {
}
// GetTwoFaStatus return state of 2FA enrollement
func (users UserList) GetTwoFaStatus() map[int64]bool {
func (users UserList) GetTwoFaStatus(ctx context.Context) map[int64]bool {
results := make(map[int64]bool, len(users))
for _, user := range users {
results[user.ID] = false // Set default to false
}
if tokenMaps, err := users.loadTwoFactorStatus(db.DefaultContext); err == nil {
if tokenMaps, err := users.loadTwoFactorStatus(ctx); err == nil {
for _, token := range tokenMaps {
results[token.UID] = true
}
}
if ids, err := users.userIDsWithWebAuthn(db.DefaultContext); err == nil {
if ids, err := users.userIDsWithWebAuthn(ctx); err == nil {
for _, id := range ids {
results[id] = true
}
@@ -71,12 +71,12 @@ func (users UserList) userIDsWithWebAuthn(ctx context.Context) ([]int64, error)
}
// GetUsersByIDs returns all resolved users from a list of Ids.
func GetUsersByIDs(ids []int64) (UserList, error) {
func GetUsersByIDs(ctx context.Context, ids []int64) (UserList, error) {
ous := make([]*User, 0, len(ids))
if len(ids) == 0 {
return ous, nil
}
err := db.GetEngine(db.DefaultContext).In("id", ids).
err := db.GetEngine(ctx).In("id", ids).
Asc("name").
Find(&ous)
return ous, err