Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-29 05:06:11 +01:00

[GITEA] notifies admins on new user registration (squash) performance bottleneck

Refs: https://codeberg.org/forgejo/forgejo/issues/1479
This commit is contained in:
JakobDev 2023-09-19 18:40:01 +02:00 committed by Earl Warren
parent 2952a184ba
commit 97ac9147ff
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 19 additions and 5 deletions

View file

@ -223,6 +223,12 @@ func GetAllUsers(ctx context.Context) ([]*User, error) {
return users, db.GetEngine(ctx).OrderBy("id").Where("type = ?", UserTypeIndividual).Find(&users) return users, db.GetEngine(ctx).OrderBy("id").Where("type = ?", UserTypeIndividual).Find(&users)
} }
// GetAllAdmins returns a slice of all adminusers found in DB.
func GetAllAdmins(ctx context.Context) ([]*User, error) {
users := make([]*User, 0)
return users, db.GetEngine(ctx).OrderBy("id").Where("type = ?", UserTypeIndividual).And("is_admin = ?", true).Find(&users)
}
// IsLocal returns true if user login type is LoginPlain. // IsLocal returns true if user login type is LoginPlain.
func (u *User) IsLocal() bool { func (u *User) IsLocal() bool {
return u.LoginType <= auth.Plain return u.LoginType <= auth.Plain

View file

@ -544,3 +544,13 @@ func Test_ValidateUser(t *testing.T) {
assert.EqualValues(t, expected, err == nil, fmt.Sprintf("case: %+v", kase)) assert.EqualValues(t, expected, err == nil, fmt.Sprintf("case: %+v", kase))
} }
} }
func TestGetAllAdmins(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
admins, err := user_model.GetAllAdmins(db.DefaultContext)
assert.NoError(t, err)
assert.Len(t, admins, 1)
assert.Equal(t, int64(1), admins[0].ID)
}

View file

@ -32,17 +32,15 @@ func MailNewUser(ctx context.Context, u *user_model.User) {
return return
} }
recipients, err := user_model.GetAllUsers(ctx) recipients, err := user_model.GetAllAdmins(ctx)
if err != nil { if err != nil {
log.Error("user_model.GetAllUsers: %v", err) log.Error("user_model.GetAllAdmins: %v", err)
return return
} }
langMap := make(map[string][]string) langMap := make(map[string][]string)
for _, r := range recipients { for _, r := range recipients {
if r.IsAdmin { langMap[r.Language] = append(langMap[r.Language], r.Email)
langMap[r.Language] = append(langMap[r.Language], r.Email)
}
} }
for lang, tos := range langMap { for lang, tos := range langMap {