Skip to content

Commit f816098

Browse files
committed
fix(document): fail to count times when cache is enabled.
1 parent effc926 commit f816098

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

cache/cache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"errors"
88
"time"
99

10-
"github.com/beego/beego/v2/core/logs"
1110
"github.com/beego/beego/v2/client/cache"
11+
"github.com/beego/beego/v2/core/logs"
1212
)
1313

1414
var bm cache.Cache

controllers/DocumentController.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,22 @@ func (c *DocumentController) Read() {
145145
}
146146

147147
doc.IncrViewCount(doc.DocumentId)
148-
c.Data["ViewCount"] = doc.ViewCount + 1
148+
doc.ViewCount = doc.ViewCount + 1
149+
doc.PutToCache()
149150

150151
if c.IsAjax() {
151152
var data struct {
152-
DocTitle string `json:"doc_title"`
153-
Body string `json:"body"`
154-
Title string `json:"title"`
155-
Version int64 `json:"version"`
156-
ViewCount int `json:"view_count"`
153+
DocTitle string `json:"doc_title"`
154+
Body string `json:"body"`
155+
Title string `json:"title"`
156+
Version int64 `json:"version"`
157+
ViewCount int `json:"view_count"`
157158
}
158159
data.DocTitle = doc.DocumentName
159160
data.Body = doc.Release
160161
data.Title = doc.DocumentName + " - Powered by MinDoc"
161162
data.Version = doc.Version
162-
data.ViewCount = doc.ViewCount + 1
163+
data.ViewCount = doc.ViewCount
163164

164165
c.JsonResult(0, "ok", data)
165166
}
@@ -178,6 +179,7 @@ func (c *DocumentController) Read() {
178179
c.Data["Result"] = template.HTML(tree)
179180
c.Data["Title"] = doc.DocumentName
180181
c.Data["Content"] = template.HTML(doc.Release)
182+
c.Data["ViewCount"] = doc.ViewCount
181183
}
182184

183185
// 编辑文档

models/DocumentModel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func (item *Document) Processor() *Document {
335335
selector.First().AppendHtml(release)
336336
}
337337
}
338-
cdnimg,_ := web.AppConfig.String("cdnimg")
338+
cdnimg, _ := web.AppConfig.String("cdnimg")
339339

340340
docQuery.Find("img").Each(func(i int, selection *goquery.Selection) {
341341

0 commit comments

Comments
 (0)