MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / InitChannelCache

Function InitChannelCache

model/channel_cache.go:22–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20var channelSyncLock sync.RWMutex
21
22func InitChannelCache() {
23 if !common.MemoryCacheEnabled {
24 return
25 }
26 newChannelId2channel := make(map[int]*Channel)
27 var channels []*Channel
28 DB.Find(&channels)
29 for _, channel := range channels {
30 newChannelId2channel[channel.Id] = channel
31 }
32 var abilities []*Ability
33 DB.Find(&abilities)
34 groups := make(map[string]bool)
35 for _, ability := range abilities {
36 groups[ability.Group] = true
37 }
38 newGroup2model2channels := make(map[string]map[string][]int)
39 for group := range groups {
40 newGroup2model2channels[group] = make(map[string][]int)
41 }
42 for _, channel := range channels {
43 if channel.Status != common.ChannelStatusEnabled {
44 continue // skip disabled channels
45 }
46 groups := strings.Split(channel.Group, ",")
47 for _, group := range groups {
48 models := strings.Split(channel.Models, ",")
49 for _, model := range models {
50 if _, ok := newGroup2model2channels[group][model]; !ok {
51 newGroup2model2channels[group][model] = make([]int, 0)
52 }
53 newGroup2model2channels[group][model] = append(newGroup2model2channels[group][model], channel.Id)
54 }
55 }
56 }
57
58 // sort by priority
59 for group, model2channels := range newGroup2model2channels {
60 for model, channels := range model2channels {
61 sort.Slice(channels, func(i, j int) bool {
62 return newChannelId2channel[channels[i]].GetPriority() > newChannelId2channel[channels[j]].GetPriority()
63 })
64 newGroup2model2channels[group][model] = channels
65 }
66 }
67
68 channelSyncLock.Lock()
69 group2model2channels = newGroup2model2channels
70 channelsIDM = newChannelId2channel
71 channelSyncLock.Unlock()
72 common.SysLog("channels synced from database")
73}
74
75func SyncChannelCache(frequency int) {
76 for {

Callers 13

mainFunction · 0.92
ImportChannelsFunction · 0.92
DeleteChannelFunction · 0.92
DeleteDisabledChannelFunction · 0.92
DisableTagChannelsFunction · 0.92
EnableTagChannelsFunction · 0.92
EditTagChannelsFunction · 0.92
DeleteChannelBatchFunction · 0.92
UpdateChannelFunction · 0.92
BatchSetChannelTagFunction · 0.92
CopyChannelFunction · 0.92
SyncChannelCacheFunction · 0.85

Calls 2

SysLogFunction · 0.92
GetPriorityMethod · 0.80

Tested by

no test coverage detected