diff --git a/controller/articlectl.go b/controller/articlectl.go index 2e26f6d1..2f86a58c 100644 --- a/controller/articlectl.go +++ b/controller/articlectl.go @@ -251,7 +251,7 @@ func showArticleAction(c *gin.Context) { c.HTML(http.StatusOK, getTheme(c)+"/article.html", dataModel) - go service.Article.IncArticleViewCount(articleModel) + service.Article.IncArticleViewCount(articleModel) } func fillPreviousArticle(c *gin.Context, article *model.Article, dataModel *DataModel) { diff --git a/controller/blogmidware.go b/controller/blogmidware.go index a9493141..f5e11b2f 100644 --- a/controller/blogmidware.go +++ b/controller/blogmidware.go @@ -77,7 +77,8 @@ func resolveBlog(c *gin.Context) { c.Set("userBlog", userBlog) fillCommon(c) - go service.Statistic.IncViewCount(userBlog.ID) + + service.Statistic.IncViewCount(userBlog.ID) path := strings.Split(c.Request.RequestURI, username)[1] path = strings.TrimSpace(path) diff --git a/service/articlesrv.go b/service/articlesrv.go index 4d3b9d1f..bd85b8ed 100644 --- a/service/articlesrv.go +++ b/service/articlesrv.go @@ -525,13 +525,15 @@ func (srv *articleService) UpdateArticle(article *model.Article) (err error) { } func (srv *articleService) IncArticleViewCount(article *model.Article) error { - srv.mutex.Lock() - defer srv.mutex.Unlock() - - article.ViewCount = article.ViewCount + 1 - if err := db.Model(&model.Article{}).Where("`id` = ?", article.ID).Select("view_count").Updates(article).Error; nil != err { - return err - } + // 浏览计数插件化 https://github.com/88250/pipe/issues/11 + + //srv.mutex.Lock() + //defer srv.mutex.Unlock() + // + //article.ViewCount = article.ViewCount + 1 + //if err := db.Model(&model.Article{}).Where("`id` = ?", article.ID).Select("view_count").Updates(article).Error; nil != err { + // return err + //} return nil } diff --git a/service/statisticsrv.go b/service/statisticsrv.go index 6acc9fe6..bac50bb6 100644 --- a/service/statisticsrv.go +++ b/service/statisticsrv.go @@ -73,13 +73,15 @@ func (srv *statisticService) GetStatistics(blogID uint, statisticNames ...string } func (srv *statisticService) IncViewCount(blogID uint64) error { - tx := db.Begin() - if err := srv.IncViewCountWithoutTx(tx, blogID); nil != err { - tx.Rollback() - - return err - } - tx.Commit() + // 浏览计数插件化 https://github.com/88250/pipe/issues/11 + + //tx := db.Begin() + //if err := srv.IncViewCountWithoutTx(tx, blogID); nil != err { + // tx.Rollback() + // + // return err + //} + //tx.Commit() return nil }