cleaned up a couple of the db functions

This commit is contained in:
Brad Rydzewski 2015-04-13 19:25:11 -07:00
parent aebacfccd7
commit 5e7c4e2573

View file

@ -93,27 +93,27 @@ func (db *DB) GetUserRepos(login string) ([]*common.Repo, error) {
// GetUserCount gets a count of all registered users // GetUserCount gets a count of all registered users
// in the system. // in the system.
func (db *DB) GetUserCount() (int, error) { func (db *DB) GetUserCount() (int, error) {
t, err := db.Begin(false) var out int
if err != nil { var err = db.View(func(t *bolt.Tx) error {
return 0, err out = t.Bucket(bucketUser).Stats().KeyN
} return nil
defer t.Rollback() })
return t.Bucket(bucketUser).Stats().KeyN, nil return out, err
} }
// GetUserList gets a list of all registered users. // GetUserList gets a list of all registered users.
func (db *DB) GetUserList() ([]*common.User, error) { func (db *DB) GetUserList() ([]*common.User, error) {
t, err := db.Begin(false)
if err != nil {
return nil, err
}
defer t.Rollback()
users := []*common.User{} users := []*common.User{}
err = t.Bucket(bucketUser).ForEach(func(key, raw []byte) error { err := db.View(func(t *bolt.Tx) error {
user := &common.User{} return t.Bucket(bucketUser).ForEach(func(key, raw []byte) error {
err := decode(raw, user) user := &common.User{}
users = append(users, user) err := decode(raw, user)
return err if err != nil {
return err
}
users = append(users, user)
return nil
})
}) })
return users, err return users, err
} }