feat: use cache to avoid database access (#158)

This commit is contained in:
JustSong committed 2023-06-20 19:09:49 +08:00
1 parent 4911d5b3b9
commit b220e8e863
5 files changed
+123 -4

No files matched your search

+2 -2
View File
@@ -17,7 +17,7 @@ type ModelRequest struct {
func Distribute() func(c *gin.Context) {
return func(c *gin.Context) {
userId := c.GetInt("id")
userGroup, _ := model.GetUserGroup(userId)
userGroup, _ := model.CacheGetUserGroup(userId)
c.Set("group", userGroup)
var channel *model.Channel
channelId, ok := c.Get("channelId")
@@ -73,7 +73,7 @@ func Distribute() func(c *gin.Context) {
modelRequest.Model = "text-moderation-stable"
}
}
channel, err = model.GetRandomSatisfiedChannel(userGroup, modelRequest.Model)
channel, err = model.CacheGetRandomSatisfiedChannel(userGroup, modelRequest.Model)
if err != nil {
c.JSON(200, gin.H{
"error": gin.H{