summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-05-21 19:50:50 +0100
committerGitHub <noreply@github.com>2022-05-21 14:50:50 -0400
commitffb7ab31f2cb3629a80e8105f84575d5b1182051 (patch)
treeae76846ec63f2456245228651b3c4be8e1535376
parent468387e9ced12367aecc8b863e20e105fbdd0c82 (diff)
downloadgitea-ffb7ab31f2cb3629a80e8105f84575d5b1182051.tar.gz
gitea-ffb7ab31f2cb3629a80e8105f84575d5b1182051.zip
Estimate Action Count in Statistics (#19775)
-rw-r--r--models/db/context.go22
-rw-r--r--models/statistic.go2
-rw-r--r--options/locale/locale_en-US.ini2
3 files changed, 24 insertions, 2 deletions
diff --git a/models/db/context.go b/models/db/context.go
index c823952cf6..dae7be3a93 100644
--- a/models/db/context.go
+++ b/models/db/context.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"xorm.io/builder"
+ "xorm.io/xorm/schemas"
)
// DefaultContext is the default context to run xorm queries in
@@ -175,3 +176,24 @@ func CountByBean(ctx context.Context, bean interface{}) (int64, error) {
func TableName(bean interface{}) string {
return x.TableName(bean)
}
+
+// EstimateCount returns an estimate of total number of rows in table
+func EstimateCount(ctx context.Context, bean interface{}) (int64, error) {
+ e := GetEngine(ctx)
+ e.Context(ctx)
+
+ var rows int64
+ var err error
+ tablename := TableName(bean)
+ switch x.Dialect().URI().DBType {
+ case schemas.MYSQL:
+ _, err = e.Context(ctx).SQL("SELECT table_rows FROM information_schema.tables WHERE tables.table_name = ? AND tables.table_schema = ?;", tablename, x.Dialect().URI().DBName).Get(&rows)
+ case schemas.POSTGRES:
+ _, err = e.Context(ctx).SQL("SELECT reltuples AS estimate FROM pg_class WHERE relname = ?;", tablename).Get(&rows)
+ case schemas.MSSQL:
+ _, err = e.Context(ctx).SQL("sp_spaceused ?;", tablename).Get(&rows)
+ default:
+ return e.Context(ctx).Count(tablename)
+ }
+ return rows, err
+}
diff --git a/models/statistic.go b/models/statistic.go
index 2b6b3a1820..dfc236ec58 100644
--- a/models/statistic.go
+++ b/models/statistic.go
@@ -56,7 +56,7 @@ func GetStatistic() (stats Statistic) {
stats.Counter.Repo, _ = repo_model.CountRepositories(db.DefaultContext, repo_model.CountRepositoryOptions{})
stats.Counter.Watch, _ = e.Count(new(repo_model.Watch))
stats.Counter.Star, _ = e.Count(new(repo_model.Star))
- stats.Counter.Action, _ = e.Count(new(Action))
+ stats.Counter.Action, _ = db.EstimateCount(db.DefaultContext, new(Action))
stats.Counter.Access, _ = e.Count(new(access_model.Access))
type IssueCount struct {
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index ba619b413c..5061c735ae 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -2423,7 +2423,7 @@ dashboard.new_version_hint = Gitea %s is now available, you are running %s. Chec
dashboard.statistic = Summary
dashboard.operations = Maintenance Operations
dashboard.system_status = System Status
-dashboard.statistic_info = The Gitea database holds <b>%d</b> users, <b>%d</b> organizations, <b>%d</b> public keys, <b>%d</b> repositories, <b>%d</b> watches, <b>%d</b> stars, <b>%d</b> actions, <b>%d</b> accesses, <b>%d</b> issues, <b>%d</b> comments, <b>%d</b> social accounts, <b>%d</b> follows, <b>%d</b> mirrors, <b>%d</b> releases, <b>%d</b> authentication sources, <b>%d</b> webhooks, <b>%d</b> milestones, <b>%d</b> labels, <b>%d</b> hook tasks, <b>%d</b> teams, <b>%d</b> update tasks, <b>%d</b> attachments.
+dashboard.statistic_info = The Gitea database holds <b>%d</b> users, <b>%d</b> organizations, <b>%d</b> public keys, <b>%d</b> repositories, <b>%d</b> watches, <b>%d</b> stars, ~<b>%d</b> actions, <b>%d</b> accesses, <b>%d</b> issues, <b>%d</b> comments, <b>%d</b> social accounts, <b>%d</b> follows, <b>%d</b> mirrors, <b>%d</b> releases, <b>%d</b> authentication sources, <b>%d</b> webhooks, <b>%d</b> milestones, <b>%d</b> labels, <b>%d</b> hook tasks, <b>%d</b> teams, <b>%d</b> update tasks, <b>%d</b> attachments.
dashboard.operation_name = Operation Name
dashboard.operation_switch = Switch
dashboard.operation_run = Run