1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 10:48:37 +00:00

Paging function for users and repositories

This commit is contained in:
Unknown
2014-07-07 04:15:08 -04:00
parent 7ffdabb28f
commit 63cc14062a
9 changed files with 71 additions and 7 deletions

View File

@@ -148,9 +148,9 @@ type Statistic struct {
}
func GetStatistic() (stats Statistic) {
stats.Counter.User, _ = x.Count(new(User))
stats.Counter.User = CountUsers()
stats.Counter.Repo = CountRepositories()
stats.Counter.PublicKey, _ = x.Count(new(PublicKey))
stats.Counter.Repo, _ = x.Count(new(Repository))
stats.Counter.Watch, _ = x.Count(new(Watch))
stats.Counter.Action, _ = x.Count(new(Action))
stats.Counter.Access, _ = x.Count(new(Access))

View File

@@ -589,6 +589,12 @@ func CreateRepository(u *User, name, desc, lang, license string, private, mirror
return repo, nil
}
// CountRepositories returns number of repositories.
func CountRepositories() int64 {
count, _ := x.Count(new(Repository))
return count
}
// GetRepositoriesWithUsers returns given number of repository objects with offset.
// It also auto-gets corresponding users.
func GetRepositoriesWithUsers(num, offset int) ([]*Repository, error) {

View File

@@ -212,6 +212,12 @@ func CreateUser(u *User) (*User, error) {
return u, err
}
// CountUsers returns number of users.
func CountUsers() int64 {
count, _ := x.Where("type=0").Count(new(User))
return count
}
// GetUsers returns given number of user objects with offset.
func GetUsers(num, offset int) ([]User, error) {
users := make([]User, 0, num)