mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
optimize sorting, fix a bug (#15)
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/robfig/cron/v3"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
)
|
||||
|
||||
@@ -83,12 +84,7 @@ func UpdateCronList() {
|
||||
CronList = append(CronList, c)
|
||||
}
|
||||
slices.SortFunc(CronList, func(a, b *model.Cron) int {
|
||||
if a.ID < b.ID {
|
||||
return -1
|
||||
} else if a.ID == b.ID {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
return utils.Compare(a.ID, b.ID)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
ddns2 "github.com/naiba/nezha/pkg/ddns"
|
||||
"github.com/naiba/nezha/pkg/ddns/dummy"
|
||||
"github.com/naiba/nezha/pkg/ddns/webhook"
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -56,12 +57,7 @@ func UpdateDDNSList() {
|
||||
DDNSList = append(DDNSList, p)
|
||||
}
|
||||
slices.SortFunc(DDNSList, func(a, b *model.DDNSProfile) int {
|
||||
if a.ID < b.ID {
|
||||
return -1
|
||||
} else if a.ID == b.ID {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
return utils.Compare(a.ID, b.ID)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -59,12 +60,7 @@ func UpdateNATList() {
|
||||
NATList = append(NATList, n)
|
||||
}
|
||||
slices.SortFunc(NATList, func(a, b *model.NAT) int {
|
||||
if a.ID < b.ID {
|
||||
return -1
|
||||
} else if a.ID == b.ID {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
return utils.Compare(a.ID, b.ID)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -85,12 +86,7 @@ func UpdateNotificationList() {
|
||||
NotificationListSorted = append(NotificationListSorted, n)
|
||||
}
|
||||
slices.SortFunc(NotificationListSorted, func(a, b *model.Notification) int {
|
||||
if a.ID < b.ID {
|
||||
return -1
|
||||
} else if a.ID == b.ID {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
return utils.Compare(a.ID, b.ID)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ func ReSortServer() {
|
||||
defer SortedServerLock.Unlock()
|
||||
|
||||
SortedServerList = make([]*model.Server, 0, len(ServerList))
|
||||
SortedServerListForGuest = make([]*model.Server, 0)
|
||||
for _, s := range ServerList {
|
||||
SortedServerList = append(SortedServerList, s)
|
||||
if !s.HideForGuest {
|
||||
|
||||
Reference in New Issue
Block a user