|
@@ -13,6 +13,10 @@ var VersionTask *Versions
|
|
|
|
|
|
|
|
type Versions struct {
|
|
type Versions struct {
|
|
|
sync.Mutex
|
|
sync.Mutex
|
|
|
|
|
+ VChannels util.SafeMap[string, *ChannelVersions]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type ChannelVersions struct {
|
|
|
VList util.SafeArray[*version.Version]
|
|
VList util.SafeArray[*version.Version]
|
|
|
VMap util.SafeMap[string, *version.Version]
|
|
VMap util.SafeMap[string, *version.Version]
|
|
|
}
|
|
}
|
|
@@ -26,21 +30,29 @@ func (this *Versions) Exec() {
|
|
|
var versions = make([]*version.Version, 0)
|
|
var versions = make([]*version.Version, 0)
|
|
|
err := mgm.Coll(&version.Version{}).SimpleFind(&versions, bson.M{})
|
|
err := mgm.Coll(&version.Version{}).SimpleFind(&versions, bson.M{})
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
- // 重置
|
|
|
|
|
- this.VList.Flush()
|
|
|
|
|
- this.VList.PushMany(versions)
|
|
|
|
|
- this.VMap.Clear()
|
|
|
|
|
|
|
+ this.VChannels.Clear()
|
|
|
for _, v := range versions {
|
|
for _, v := range versions {
|
|
|
- this.VMap.Set(v.Version, v)
|
|
|
|
|
|
|
+ if _, ok := this.VChannels.Get(v.Channel); !ok {
|
|
|
|
|
+ this.VChannels.Set(v.Channel, new(ChannelVersions))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ channelVersion, _ := this.VChannels.Get(v.Channel)
|
|
|
|
|
+ channelVersion.VList.Push(v)
|
|
|
|
|
+ channelVersion.VMap.Set(v.Version, v)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (this *Versions) Check(version string, channel string) *version.Version {
|
|
func (this *Versions) Check(version string, channel string) *version.Version {
|
|
|
- data, ok := this.VMap.Get(version)
|
|
|
|
|
|
|
+ channelVersions, ok := this.VChannels.Get(channel)
|
|
|
if !ok { // 遍历列表
|
|
if !ok { // 遍历列表
|
|
|
- for _, v := range this.VList.View() {
|
|
|
|
|
- if v.Default && v.Channel == channel {
|
|
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ data, ok := channelVersions.VMap.Get(version)
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ for _, v := range channelVersions.VList.View() {
|
|
|
|
|
+ if v.Default && v.Version == version && v.Channel == channel {
|
|
|
data = v
|
|
data = v
|
|
|
break
|
|
break
|
|
|
}
|
|
}
|
|
@@ -52,11 +64,12 @@ func (this *Versions) Check(version string, channel string) *version.Version {
|
|
|
|
|
|
|
|
func (this *Versions) Servers(channel string) []*version.Version {
|
|
func (this *Versions) Servers(channel string) []*version.Version {
|
|
|
var res = make([]*version.Version, 0)
|
|
var res = make([]*version.Version, 0)
|
|
|
- for _, v := range this.VList.View() {
|
|
|
|
|
- if v.Channel == channel {
|
|
|
|
|
- res = append(res, v)
|
|
|
|
|
|
|
+ if channelVersions, ok := this.VChannels.Get(channel); ok {
|
|
|
|
|
+ for _, v := range channelVersions.VList.View() {
|
|
|
|
|
+ if v.Channel == channel {
|
|
|
|
|
+ res = append(res, v)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return res
|
|
return res
|
|
|
}
|
|
}
|