add conversationCache

This commit is contained in:
wangchuxiao
2022-08-21 17:33:40 +08:00
parent 840e08fc8a
commit ee577cae4c
4 changed files with 60 additions and 12 deletions
+15 -3
View File
@@ -465,7 +465,7 @@ func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversat
bytes, err := json.Marshal(conversation)
return string(bytes), utils.Wrap(err, "")
}
conversationStr, err := db.DB.Rc.Fetch(conversationCache+conversationID, time.Second*30*60, getConversation)
conversationStr, err := db.DB.Rc.Fetch(conversationCache+ownerUserID+":"+conversationID, time.Second*30*60, getConversation)
conversation := db.Conversation{}
err = json.Unmarshal([]byte(conversationStr), &conversation)
if err != nil {
@@ -474,6 +474,18 @@ func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversat
return &conversation, nil
}
func GetConversationsFromCache(ownerUserID string, conversationIDList []string) ([]db.Conversation, error) {
var conversationList []db.Conversation
for _, conversationID := range conversationIDList {
conversation, err := GetConversationFromCache(ownerUserID, conversationID)
if err != nil {
return nil, utils.Wrap(err, "GetConversationFromCache failed")
}
conversationList = append(conversationList, *conversation)
}
return conversationList, nil
}
func GetUserAllConversationList(ownerUserID string) ([]db.Conversation, error) {
IDList, err := GetUserConversationIDListFromCache(ownerUserID)
if err != nil {
@@ -490,6 +502,6 @@ func GetUserAllConversationList(ownerUserID string) ([]db.Conversation, error) {
return conversationList, nil
}
func DelConversationFromCache(conversationID string) error {
return db.DB.Rc.TagAsDeleted(conversationCache + conversationID)
func DelConversationFromCache(ownerUserID, conversationID string) error {
return db.DB.Rc.TagAsDeleted(conversationCache + ownerUserID + ":" + conversationID)
}