You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.1 KiB
84 lines
2.1 KiB
8 months ago
|
// Copyright © 2024 OpenIM. All rights reserved.
|
||
|
//
|
||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
// you may not use this file except in compliance with the License.
|
||
|
// You may obtain a copy of the License at
|
||
|
//
|
||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||
|
//
|
||
|
// Unless required by applicable law or agreed to in writing, software
|
||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
// See the License for the specific language governing permissions and
|
||
|
// limitations under the License.
|
||
|
|
||
6 months ago
|
package localcache
|
||
8 months ago
|
|
||
|
import (
|
||
6 months ago
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache/cachekey"
|
||
8 months ago
|
"strings"
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
once sync.Once
|
||
|
subscribe map[string][]string
|
||
|
)
|
||
|
|
||
7 months ago
|
func InitLocalCache(localCache *config.LocalCache) {
|
||
8 months ago
|
once.Do(func() {
|
||
|
list := []struct {
|
||
7 months ago
|
Local config.CacheConfig
|
||
8 months ago
|
Keys []string
|
||
|
}{
|
||
|
{
|
||
7 months ago
|
Local: localCache.User,
|
||
8 months ago
|
Keys: []string{cachekey.UserInfoKey, cachekey.UserGlobalRecvMsgOptKey},
|
||
|
},
|
||
|
{
|
||
7 months ago
|
Local: localCache.Group,
|
||
8 months ago
|
Keys: []string{cachekey.GroupMemberIDsKey, cachekey.GroupInfoKey, cachekey.GroupMemberInfoKey},
|
||
|
},
|
||
|
{
|
||
7 months ago
|
Local: localCache.Friend,
|
||
8 months ago
|
Keys: []string{cachekey.FriendIDsKey, cachekey.BlackIDsKey},
|
||
|
},
|
||
|
{
|
||
7 months ago
|
Local: localCache.Conversation,
|
||
8 months ago
|
Keys: []string{cachekey.ConversationKey, cachekey.ConversationIDsKey, cachekey.ConversationNotReceiveMessageUserIDsKey},
|
||
|
},
|
||
|
}
|
||
|
subscribe = make(map[string][]string)
|
||
|
for _, v := range list {
|
||
|
if v.Local.Enable() {
|
||
|
subscribe[v.Local.Topic] = v.Keys
|
||
|
}
|
||
|
}
|
||
|
})
|
||
7 months ago
|
}
|
||
|
|
||
6 months ago
|
func GetPublishKeysByTopic(topics []string, keys []string) map[string][]string {
|
||
|
keysByTopic := make(map[string][]string)
|
||
|
for _, topic := range topics {
|
||
|
keysByTopic[topic] = []string{}
|
||
8 months ago
|
}
|
||
6 months ago
|
|
||
|
for _, key := range keys {
|
||
|
for _, topic := range topics {
|
||
|
prefixes, ok := subscribe[topic]
|
||
|
if !ok {
|
||
|
continue
|
||
|
}
|
||
|
for _, prefix := range prefixes {
|
||
|
if strings.HasPrefix(key, prefix) {
|
||
|
keysByTopic[topic] = append(keysByTopic[topic], key)
|
||
|
break
|
||
|
}
|
||
8 months ago
|
}
|
||
|
}
|
||
|
}
|
||
6 months ago
|
|
||
|
return keysByTopic
|
||
8 months ago
|
}
|