Commit 0fd6edab by Arve Knudsen Committed by GitHub

services/sqlstore: Order results in UserSearch by username/email (#23328)

* services/sqlstore: Order results in UserSearch by username/email
* Add index (login,email) on user table
parent b86789c6
......@@ -122,6 +122,10 @@ func addUserMigrations(mg *Migrator) {
mg.AddMigration("Add is_disabled column to user", NewAddColumnMigration(userV2, &Column{
Name: "is_disabled", Type: DB_Bool, Nullable: false, Default: "0",
}))
mg.AddMigration("Add index user.login/user.email", NewAddIndexMigration(userV2, &Index{
Cols: []string{"login", "email"},
}))
}
type AddMissingUserSaltAndRandsMigration struct {
......
......@@ -68,7 +68,6 @@ func (ss *SqlStore) Init() error {
ss.readConfig()
engine, err := ss.getEngine()
if err != nil {
return fmt.Errorf("Fail to connect to database: %v", err)
}
......@@ -232,7 +231,6 @@ func (ss *SqlStore) buildConnectionString() (string, error) {
func (ss *SqlStore) getEngine() (*xorm.Engine, error) {
connectionString, err := ss.buildConnectionString()
if err != nil {
return nil, err
}
......
......@@ -454,7 +454,7 @@ func SearchUsers(query *models.SearchUsersQuery) error {
offset := query.Limit * (query.Page - 1)
sess.Limit(query.Limit, offset)
sess.Cols("u.id", "u.email", "u.name", "u.login", "u.is_admin", "u.is_disabled", "u.last_seen_at", "user_auth.auth_module")
sess.OrderBy("u.id")
sess.Asc("u.login", "u.email")
if err := sess.Find(&query.Result.Users); err != nil {
return err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment