diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/models.go | 4 | ||||
-rw-r--r-- | models/repo.go | 6 | ||||
-rw-r--r-- | models/user.go | 6 |
3 files changed, 14 insertions, 2 deletions
diff --git a/models/models.go b/models/models.go index 070784f137..ded8b05984 100644 --- a/models/models.go +++ b/models/models.go @@ -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)) diff --git a/models/repo.go b/models/repo.go index 35e4427577..396e536e4b 100644 --- a/models/repo.go +++ b/models/repo.go @@ -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) { diff --git a/models/user.go b/models/user.go index b98e81babe..47f1d45f0e 100644 --- a/models/user.go +++ b/models/user.go @@ -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) |