cleaned up a couple of the db functions
This commit is contained in:
parent
aebacfccd7
commit
5e7c4e2573
1 changed files with 16 additions and 16 deletions
|
@ -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 {
|
||||||
|
return t.Bucket(bucketUser).ForEach(func(key, raw []byte) error {
|
||||||
user := &common.User{}
|
user := &common.User{}
|
||||||
err := decode(raw, user)
|
err := decode(raw, user)
|
||||||
users = append(users, user)
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
users = append(users, user)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
})
|
})
|
||||||
return users, err
|
return users, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue