mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-08 06:15:40 +00:00
compile only once for regexp.MustCompile
Signed-off-by: pei0804 <peeeei0804@gmail.com>
This commit is contained in:
1
changelogs/unreleased/1306-pei0804
Normal file
1
changelogs/unreleased/1306-pei0804
Normal file
@@ -0,0 +1 @@
|
||||
compile only once to lower the initialization cost for regexp.MustCompile.
|
||||
@@ -45,11 +45,12 @@ func printBackupList(list *velerov1api.BackupList, w io.Writer, options printers
|
||||
return nil
|
||||
}
|
||||
|
||||
// sort by default alphabetically, but if backups stem from a common schedule
|
||||
// (detected by the presence of a 14-digit timestamp suffix), then within that
|
||||
// group, sort by newest to oldest (i.e. prefix ASC, suffix DESC)
|
||||
var timestampSuffix = regexp.MustCompile("-[0-9]{14}$")
|
||||
|
||||
func sortBackupsByPrefixAndTimestamp(list *velerov1api.BackupList) {
|
||||
// sort by default alphabetically, but if backups stem from a common schedule
|
||||
// (detected by the presence of a 14-digit timestamp suffix), then within that
|
||||
// group, sort by newest to oldest (i.e. prefix ASC, suffix DESC)
|
||||
timestampSuffix := regexp.MustCompile("-[0-9]{14}$")
|
||||
|
||||
sort.Slice(list.Items, func(i, j int) bool {
|
||||
iSuffixIndex := timestampSuffix.FindStringIndex(list.Items[i].Name)
|
||||
|
||||
Reference in New Issue
Block a user