Repository: go-gitea/gitea
File: models/user/user.go (Go)

Code before:
	emailAddresses := make([]*EmailAddress, 0, len(needCheckEmails))
	if err := db.GetEngine(ctx).In("lower_email", needCheckEmails.Values()).
		And("is_activated=?", true).
		Find(&emailAddresses); err != nil {
		return nil, err
	}
	userIDs := make(container.Set[int64])
	for _, email := range emailAddresses {
		userIDs.Add(email.UID)
	}
	results := make(map[string]*User, len(emails))

	if len(userIDs) > 0 {
		users, err := GetUsersMapByIDs(ctx, userIDs.Values())
		if err != nil {
			return nil, err
		}

		for _, email := range emailAddresses {
			user := users[email.UID]
			if user != nil {
				if user.KeepEmailPrivate {
					results[user.LowerName+"@"+setting.Service.NoReplyAddress] = user
				} else {
					results[email.Email] = user
				}
			}
		}
	}

	users := make(map[int64]*User, len(needCheckUserNames))
	if err := db.GetEngine(ctx).In("lower_name", needCheckUserNames.Values()).Find(&users); err != nil {
		return nil, err
	}
	for _, user := range users {
		results[user.LowerName+"@"+setting.Service.NoReplyAddress] = user
	}
	return results, nil
}

// GetUserByEmail returns the user object by given e-mail if exists.
func GetUserByEmail(ctx context.Context, email string) (*User, error) {
	if len(email) == 0 {
		return nil, ErrUserNotExist{Name: email}
	}

	email = strings.ToLower(email)
	// Otherwise, check in alternative list for activated email addresses
	emailAddress := &EmailAddress{LowerEmail: email, IsActivated: true}
	has, err := db.GetEngine(ctx).Get(emailAddress)
	if err != nil {

Review comment (suggestion):
![image](https://github.com/user-attachments/assets/5019c06e-cf3e-4e8a-8d3d-0673411db776)
You can use `user.GetPlaceholderEmail()` directly

Code after:
	emailAddresses := make([]*EmailAddress, 0, len(needCheckEmails))
	if err := db.GetEngine(ctx).In("lower_email", needCheckEmails.Values()).
		And("is_activated=?", true).
		Find(&emailAddresses); err != nil {
		return nil, err
	}
	userIDs := make(container.Set[int64])
	for _, email := range emailAddresses {
		userIDs.Add(email.UID)
	}
	results := make(map[string]*User, len(emails))

	if len(userIDs) > 0 {
		users, err := GetUsersMapByIDs(ctx, userIDs.Values())
		if err != nil {
			return nil, err
		}

		for _, email := range emailAddresses {
			user := users[email.UID]
			if user != nil {
				results[user.GetEmail()] = user
			}
		}
	}

	users := make(map[int64]*User, len(needCheckUserNames))
	if err := db.GetEngine(ctx).In("lower_name", needCheckUserNames.Values()).Find(&users); err != nil {
		return nil, err
	}
	for _, user := range users {
		results[user.GetPlaceholderEmail()] = user
	}
	return results, nil
}

// GetUserByEmail returns the user object by given e-mail if exists.
func GetUserByEmail(ctx context.Context, email string) (*User, error) {
	if len(email) == 0 {
		return nil, ErrUserNotExist{Name: email}
	}

	email = strings.ToLower(email)
	// Otherwise, check in alternative list for activated email addresses
	emailAddress := &EmailAddress{LowerEmail: email, IsActivated: true}
	has, err := db.GetEngine(ctx).Get(emailAddress)
	if err != nil {
		return nil, err
	}
	if has {
		return GetUserByID(ctx, emailAddress.UID)