[GITEA] notifies admins on new user registration (squash) performance bottleneck
Refs: https://codeberg.org/forgejo/forgejo/issues/1479
This commit is contained in:
parent
2952a184ba
commit
97ac9147ff
3 changed files with 19 additions and 5 deletions
|
@ -223,6 +223,12 @@ func GetAllUsers(ctx context.Context) ([]*User, error) {
|
|||
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.
|
||||
func (u *User) IsLocal() bool {
|
||||
return u.LoginType <= auth.Plain
|
||||
|
|
|
@ -544,3 +544,13 @@ func Test_ValidateUser(t *testing.T) {
|
|||
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)
|
||||
}
|
||||
|
|
|
@ -32,17 +32,15 @@ func MailNewUser(ctx context.Context, u *user_model.User) {
|
|||
return
|
||||
}
|
||||
|
||||
recipients, err := user_model.GetAllUsers(ctx)
|
||||
recipients, err := user_model.GetAllAdmins(ctx)
|
||||
if err != nil {
|
||||
log.Error("user_model.GetAllUsers: %v", err)
|
||||
log.Error("user_model.GetAllAdmins: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
langMap := make(map[string][]string)
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue