Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
fix(cache): ChildCommentCacheSave repeatedly cache while exist
Browse files Browse the repository at this point in the history
Signed-off-by: qwqcode <[email protected]>
  • Loading branch information
qwqcode committed Apr 23, 2022
1 parent 12ee6ab commit 3f1313a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions model/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func FindCache(name string, destStruct interface{}) (cacher, error) {
return cacher, err
}

str := entry.([]byte)
err = json.Unmarshal(str, destStruct)
str := fmt.Sprintf("%s", entry)
err = json.Unmarshal([]byte(str), destStruct)
if err != nil {
logrus.Debug("[缓存反序列化错误] ", name, " ", err)

Expand Down Expand Up @@ -211,7 +211,19 @@ func ChildCommentCacheSave(parentID uint, childID uint) {
// 初始化
childIDs = []uint{}
}
childIDs = append(childIDs, childID)

isExist := false
for _, i := range childIDs {
if i == childID {
isExist = true
break
}
}

// append if Not exist
if !isExist {
childIDs = append(childIDs, childID)
}

return &childIDs
})
Expand Down

0 comments on commit 3f1313a

Please sign in to comment.