Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions models/db/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ import (
// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
func BuildCaseInsensitiveLike(key, value string) builder.Cond {
if setting.Database.Type.IsSQLite3() {
return builder.Like{"UPPER(" + key + ")", util.ToUpperASCII(value)}
return builder.Expr(key+" LIKE ? COLLATE NOCASE", value)
}
Comment thread
tyroneyeh marked this conversation as resolved.
Outdated
return builder.Like{"UPPER(" + key + ")", strings.ToUpper(value)}
if setting.Database.Type.IsPostgreSQL() {
return builder.Expr(key+" ILIKE ?", value)
}
return builder.Like{"LOWER(" + key + ")", strings.ToLower(value)}
Comment thread
tyroneyeh marked this conversation as resolved.
}

// BuildCaseInsensitiveIn returns a condition to check if the given value is in the given values case-insensitively.
// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
func BuildCaseInsensitiveIn(key string, values []string) builder.Cond {
uppers := make([]string, 0, len(values))
if setting.Database.Type.IsPostgreSQL() {
return builder.Expr(key+" ILIKE ANY (ARRAY[?])", values)
}
Comment thread
tyroneyeh marked this conversation as resolved.
Outdated
uppers := make([]string, len(values))
transform := strings.ToUpper
if setting.Database.Type.IsSQLite3() {
for _, value := range values {
uppers = append(uppers, util.ToUpperASCII(value))
}
} else {
for _, value := range values {
uppers = append(uppers, strings.ToUpper(value))
}
transform = util.ToUpperASCII
}
for i, value := range values {
uppers[i] = transform(value)
}

return builder.In("UPPER("+key+")", uppers)
Expand Down
2 changes: 1 addition & 1 deletion models/repo/user_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us
func GetIssuePostersWithSearch(ctx context.Context, repo *Repository, isPull bool, search string, isShowFullName bool) ([]*user_model.User, error) {
users := make([]*user_model.User, 0, 30)
var prefixCond builder.Cond = builder.Like{"lower_name", strings.ToLower(search) + "%"}
if isShowFullName {
if search != "" && isShowFullName {
prefixCond = prefixCond.Or(db.BuildCaseInsensitiveLike("full_name", "%"+search+"%"))
}

Expand Down
Loading