2019-12-08 03:59:58 -05:00
|
|
|
package dao
|
|
|
|
|
|
|
|
import (
|
2021-01-08 08:04:50 -05:00
|
|
|
"sort"
|
2019-12-09 05:14:31 -05:00
|
|
|
"sync"
|
|
|
|
|
2019-12-08 03:59:58 -05:00
|
|
|
"github.com/patrickmn/go-cache"
|
2020-12-19 10:11:16 -05:00
|
|
|
"gorm.io/gorm"
|
2019-12-08 03:59:58 -05:00
|
|
|
|
2020-11-10 21:07:45 -05:00
|
|
|
"github.com/naiba/nezha/model"
|
2019-12-08 03:59:58 -05:00
|
|
|
)
|
|
|
|
|
2020-12-19 23:18:27 -05:00
|
|
|
const (
|
|
|
|
SnapshotDelay = 3
|
|
|
|
ReportDelay = 2
|
|
|
|
)
|
|
|
|
|
2019-12-08 03:59:58 -05:00
|
|
|
var Conf *model.Config
|
|
|
|
|
|
|
|
var Cache *cache.Cache
|
|
|
|
|
|
|
|
var DB *gorm.DB
|
|
|
|
|
2021-01-08 08:04:50 -05:00
|
|
|
var ServerList map[uint64]*model.Server
|
2019-12-09 05:14:31 -05:00
|
|
|
var ServerLock sync.RWMutex
|
2019-12-09 10:45:23 -05:00
|
|
|
|
2021-01-17 09:18:36 -05:00
|
|
|
var SortedServerList []*model.Server
|
|
|
|
var SortedServerLock sync.RWMutex
|
|
|
|
|
2021-01-17 20:42:44 -05:00
|
|
|
var Version = "v0.2.5"
|
2020-10-28 23:20:32 -04:00
|
|
|
|
2021-01-08 08:04:50 -05:00
|
|
|
func ReSortServer() {
|
2021-01-17 09:18:36 -05:00
|
|
|
ServerLock.RLock()
|
|
|
|
defer ServerLock.RUnlock()
|
|
|
|
SortedServerLock.Lock()
|
|
|
|
defer SortedServerLock.Unlock()
|
|
|
|
|
2021-01-08 08:04:50 -05:00
|
|
|
SortedServerList = []*model.Server{}
|
|
|
|
for _, s := range ServerList {
|
|
|
|
SortedServerList = append(SortedServerList, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.SliceStable(SortedServerList, func(i, j int) bool {
|
|
|
|
return SortedServerList[i].DisplayIndex > SortedServerList[j].DisplayIndex
|
|
|
|
})
|
|
|
|
}
|