Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
23 changes: 13 additions & 10 deletions models/db/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@ import (
"xorm.io/builder"
)

// BuildCaseInsensitiveLike returns a condition to check if the given value is like the given key case-insensitively.
// BuildCaseInsensitiveLike returns a case-insensitive LIKE condition for the given key and value.
// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
// PostgreSQL uses ILIKE for pattern matching.
// Other databases use LOWER(column) + LOWER(value) for case-insensitive matching.
func BuildCaseInsensitiveLike(key, value string) builder.Cond {
if setting.Database.Type.IsSQLite3() {
return builder.Like{"UPPER(" + key + ")", util.ToUpperASCII(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))
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