aboutsummaryrefslogtreecommitdiffstats
path: root/models/user
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-05-02 15:35:45 +0200
committerGitHub <noreply@github.com>2022-05-02 21:35:45 +0800
commite2a3f3d259d230b7d1f62138e789ccdfd8f43b73 (patch)
treebfb79a507a767f82f0ecf695eea66c2777d2f09d /models/user
parent509d8112432bd90f070e35e03f4cf78a416914fc (diff)
downloadgitea-e2a3f3d259d230b7d1f62138e789ccdfd8f43b73.tar.gz
gitea-e2a3f3d259d230b7d1f62138e789ccdfd8f43b73.zip
Federation: return useful statistic information for nodeinfo (#19561)
Add statistic information for total user count, active user count, issue count and comment count for `/nodeinfo`
Diffstat (limited to 'models/user')
-rw-r--r--models/user/user.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/models/user/user.go b/models/user/user.go
index 5b556c9884..6aa63a0a56 100644
--- a/models/user/user.go
+++ b/models/user/user.go
@@ -744,16 +744,25 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
return committer.Commit()
}
-func countUsers(e db.Engine) int64 {
- count, _ := e.
- Where("type=0").
- Count(new(User))
- return count
+// CountUserFilter represent optional filters for CountUsers
+type CountUserFilter struct {
+ LastLoginSince *int64
}
// CountUsers returns number of users.
-func CountUsers() int64 {
- return countUsers(db.GetEngine(db.DefaultContext))
+func CountUsers(opts *CountUserFilter) int64 {
+ return countUsers(db.DefaultContext, opts)
+}
+
+func countUsers(ctx context.Context, opts *CountUserFilter) int64 {
+ sess := db.GetEngine(ctx).Where(builder.Eq{"type": "0"})
+
+ if opts != nil && opts.LastLoginSince != nil {
+ sess = sess.Where(builder.Gte{"last_login_unix": *opts.LastLoginSince})
+ }
+
+ count, _ := sess.Count(new(User))
+ return count
}
// GetVerifyUser get user by verify code