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
9 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
|
||
9 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"
|
||
9 months ago
|
"strings"
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
once sync.Once
|
||
|
subscribe map[string][]string
|
||
|
)
|
||
|
|
||
8 months ago
|
func InitLocalCache(localCache *config.LocalCache) {
|
||
9 months ago
|
once.Do(func() {
|
||
|
list := []struct {
|
||
8 months ago
|
Local config.CacheConfig
|
||
9 months ago
|
Keys []string
|
||
|
}{
|
||
|
{
|
||
8 months ago
|
Local: localCache.User,
|
||
9 months ago
|
Keys: []string{cachekey.UserInfoKey, cachekey.UserGlobalRecvMsgOptKey},
|
||
|
},
|
||
|
{
|
||
8 months ago
|
Local: localCache.Group,
|
||
9 months ago
|
Keys: []string{cachekey.GroupMemberIDsKey, cachekey.GroupInfoKey, cachekey.GroupMemberInfoKey},
|
||
|
},
|
||
|
{
|
||
8 months ago
|
Local: localCache.Friend,
|
||
9 months ago
|
Keys: []string{cachekey.FriendIDsKey, cachekey.BlackIDsKey},
|
||
|
},
|
||
|
{
|
||
8 months ago
|
Local: localCache.Conversation,
|
||
9 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
|
||
|
}
|
||
|
}
|
||
|
})
|
||
8 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{}
|
||
9 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
|
||
|
}
|
||
9 months ago
|
}
|
||
|
}
|
||
|
}
|
||
6 months ago
|
|
||
|
return keysByTopic
|
||
9 months ago
|
}
|