diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-12-11 23:55:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-11 15:55:10 +0000 |
commit | f2a309e6c81f9ce0de5346e49efbc98fbd20e54b (patch) | |
tree | c23f8ecdd658b598c1e73927f0792bbf671cf600 /modules/doctor | |
parent | 537fa6996214ef42348cfe89bab6f2e04380aeac (diff) | |
download | gitea-f2a309e6c81f9ce0de5346e49efbc98fbd20e54b.tar.gz gitea-f2a309e6c81f9ce0de5346e49efbc98fbd20e54b.zip |
Improve doctor cli behavior (#28422)
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
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 }) } |