Skip to content

Commit 7555f3a

Browse files
committed
#11 取消本地浏览计数
1 parent f42a688 commit 7555f3a

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

controller/articlectl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func showArticleAction(c *gin.Context) {
251251

252252
c.HTML(http.StatusOK, getTheme(c)+"/article.html", dataModel)
253253

254-
go service.Article.IncArticleViewCount(articleModel)
254+
service.Article.IncArticleViewCount(articleModel)
255255
}
256256

257257
func fillPreviousArticle(c *gin.Context, article *model.Article, dataModel *DataModel) {

controller/blogmidware.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func resolveBlog(c *gin.Context) {
7777
c.Set("userBlog", userBlog)
7878

7979
fillCommon(c)
80-
go service.Statistic.IncViewCount(userBlog.ID)
80+
81+
service.Statistic.IncViewCount(userBlog.ID)
8182

8283
path := strings.Split(c.Request.RequestURI, username)[1]
8384
path = strings.TrimSpace(path)

service/articlesrv.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,15 @@ func (srv *articleService) UpdateArticle(article *model.Article) (err error) {
525525
}
526526

527527
func (srv *articleService) IncArticleViewCount(article *model.Article) error {
528-
srv.mutex.Lock()
529-
defer srv.mutex.Unlock()
530-
531-
article.ViewCount = article.ViewCount + 1
532-
if err := db.Model(&model.Article{}).Where("`id` = ?", article.ID).Select("view_count").Updates(article).Error; nil != err {
533-
return err
534-
}
528+
// 浏览计数插件化 https://github.com/88250/pipe/issues/11
529+
530+
//srv.mutex.Lock()
531+
//defer srv.mutex.Unlock()
532+
//
533+
//article.ViewCount = article.ViewCount + 1
534+
//if err := db.Model(&model.Article{}).Where("`id` = ?", article.ID).Select("view_count").Updates(article).Error; nil != err {
535+
// return err
536+
//}
535537

536538
return nil
537539
}

service/statisticsrv.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ func (srv *statisticService) GetStatistics(blogID uint, statisticNames ...string
7373
}
7474

7575
func (srv *statisticService) IncViewCount(blogID uint64) error {
76-
tx := db.Begin()
77-
if err := srv.IncViewCountWithoutTx(tx, blogID); nil != err {
78-
tx.Rollback()
79-
80-
return err
81-
}
82-
tx.Commit()
76+
// 浏览计数插件化 https://github.com/88250/pipe/issues/11
77+
78+
//tx := db.Begin()
79+
//if err := srv.IncViewCountWithoutTx(tx, blogID); nil != err {
80+
// tx.Rollback()
81+
//
82+
// return err
83+
//}
84+
//tx.Commit()
8385

8486
return nil
8587
}

0 commit comments

Comments
 (0)