From 13b9e1a1cb0e3a14da9a536c1ac0cf2cdf7430df Mon Sep 17 00:00:00 2001 From: Minho Date: Mon, 12 Mar 2018 16:24:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8E=86=E5=8F=B2=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E4=BF=9D=E5=AD=98=E9=80=BB=E8=BE=91=EF=BC=8C=E5=8F=AA?= =?UTF-8?q?=E6=9C=89=E4=B8=A4=E6=AC=A1=E6=96=87=E6=A1=A3=E5=86=85=E5=AE=B9?= =?UTF-8?q?MD5=E5=80=BC=E4=B8=80=E8=87=B4=E6=97=B6=E6=89=8D=E4=BF=9D?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/document.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/controllers/document.go b/controllers/document.go index 8e64865c..cd35e52d 100644 --- a/controllers/document.go +++ b/controllers/document.go @@ -26,6 +26,7 @@ import ( "github.com/lifei6671/mindoc/utils" "github.com/lifei6671/mindoc/utils/pagination" "gopkg.in/russross/blackfriday.v2" + "github.com/lifei6671/mindoc/utils/cryptil" ) // DocumentController struct @@ -805,12 +806,16 @@ func (c *DocumentController) Content() { } // 如果启用了文档历史,则添加历史文档 - if c.EnableDocumentHistory { - _, err = history.InsertOrUpdate() - if err != nil { - beego.Error("DocumentHistory InsertOrUpdate => ", err) + ///如果两次保存的MD5值不同则保存为历史,否则忽略 + go func(history *models.DocumentHistory) { + if c.EnableDocumentHistory && cryptil.Md5Crypt(history.Markdown) != cryptil.Md5Crypt(doc.Markdown) { + _, err = history.InsertOrUpdate() + if err != nil { + beego.Error("DocumentHistory InsertOrUpdate => ", err) + } } - } + }(history) + //如果启用了自动发布 if autoRelease { go func(identify string) {