优化历史文档保存逻辑,只有两次文档内容MD5值一致时才保存

pull/219/merge
Minho 2018-03-12 16:24:44 +08:00
parent e5c758c38b
commit 13b9e1a1cb
1 changed files with 10 additions and 5 deletions

View File

@ -26,6 +26,7 @@ import (
"github.com/lifei6671/mindoc/utils" "github.com/lifei6671/mindoc/utils"
"github.com/lifei6671/mindoc/utils/pagination" "github.com/lifei6671/mindoc/utils/pagination"
"gopkg.in/russross/blackfriday.v2" "gopkg.in/russross/blackfriday.v2"
"github.com/lifei6671/mindoc/utils/cryptil"
) )
// DocumentController struct // DocumentController struct
@ -805,12 +806,16 @@ func (c *DocumentController) Content() {
} }
// 如果启用了文档历史,则添加历史文档 // 如果启用了文档历史,则添加历史文档
if c.EnableDocumentHistory { ///如果两次保存的MD5值不同则保存为历史否则忽略
go func(history *models.DocumentHistory) {
if c.EnableDocumentHistory && cryptil.Md5Crypt(history.Markdown) != cryptil.Md5Crypt(doc.Markdown) {
_, err = history.InsertOrUpdate() _, err = history.InsertOrUpdate()
if err != nil { if err != nil {
beego.Error("DocumentHistory InsertOrUpdate => ", err) beego.Error("DocumentHistory InsertOrUpdate => ", err)
} }
} }
}(history)
//如果启用了自动发布 //如果启用了自动发布
if autoRelease { if autoRelease {
go func(identify string) { go func(identify string) {