diff options
author | Giteabot <teabot@gitea.io> | 2023-12-12 00:28:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-11 16:28:27 +0000 |
commit | 1ec622db243ef97432989751f083d308fde7c2fb (patch) | |
tree | 2431961b1361f65f418e4c504383e11d17d4f11e /modules/doctor | |
parent | 40d51188c039f6a674a37e67d0ea5504a7a3e282 (diff) | |
download | gitea-1ec622db243ef97432989751f083d308fde7c2fb.tar.gz gitea-1ec622db243ef97432989751f083d308fde7c2fb.zip |
Improve doctor cli behavior (#28422) (#28424)
Backport #28422 by wxiaoguang
1. Do not sort the "checks" slice again and again when "Register", it
just wastes CPU when the Gitea instance runs
2. If a check doesn't exist, tell the end user
3. Add some tests
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/doctor')
-rw-r--r-- | modules/doctor/doctor.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/modules/doctor/doctor.go b/modules/doctor/doctor.go index ceee322852..559f8e06da 100644 --- a/modules/doctor/doctor.go +++ b/modules/doctor/doctor.go @@ -79,6 +79,7 @@ var Checks []*Check // RunChecks runs the doctor checks for the provided list func RunChecks(ctx context.Context, colorize, autofix bool, checks []*Check) error { + SortChecks(checks) // the checks output logs by a special logger, they do not use the default logger logger := log.BaseLoggerToGeneralLogger(&doctorCheckLogger{colorize: colorize}) loggerStep := log.BaseLoggerToGeneralLogger(&doctorCheckStepLogger{colorize: colorize}) @@ -104,20 +105,23 @@ func RunChecks(ctx context.Context, colorize, autofix bool, checks []*Check) err logger.Info("OK") } } - logger.Info("\nAll done.") + logger.Info("\nAll done (checks: %d).", len(checks)) return nil } // Register registers a command with the list func Register(command *Check) { Checks = append(Checks, command) - sort.SliceStable(Checks, func(i, j int) bool { - if Checks[i].Priority == Checks[j].Priority { - return Checks[i].Name < Checks[j].Name +} + +func SortChecks(checks []*Check) { + sort.SliceStable(checks, func(i, j int) bool { + if checks[i].Priority == checks[j].Priority { + return checks[i].Name < checks[j].Name } - if Checks[i].Priority == 0 { + if checks[i].Priority == 0 { return false } - return Checks[i].Priority < Checks[j].Priority + return checks[i].Priority < checks[j].Priority }) } |