From 4b92636079e9b736795c94e0d367d9c37c6526c4 Mon Sep 17 00:00:00 2001 From: deepzz0 Date: Wed, 28 Apr 2021 16:28:14 +0800 Subject: [PATCH] fix: bugs --- pkg/cache/cache.go | 17 ++++++++--------- pkg/cache/store/mongodb.go | 4 +--- pkg/core/blog/admin/admin.go | 4 ++-- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 912cccd..87be8c4 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -235,7 +235,7 @@ func (c *Cache) PageArticleBE(se int, kw string, draft, del bool, p, return nil, 0 } max := count / n - if max%n > 0 { + if count%n > 0 { max++ } return articles, max @@ -257,11 +257,12 @@ func (c *Cache) refreshCache(article *model.Article, del bool) { _, idx := c.FindArticleByID(article.ID) delete(c.ArticlesMap, article.Slug) - c.Articles = append(Ei.Articles[:idx], Ei.Articles[idx+1:]...) + c.Articles = append(c.Articles[:idx], c.Articles[idx+1:]...) // 从链表移除 c.recalcLinkedList(article, true) // 从tag、serie、archive移除 c.redelArticle(article) + return } // 添加文章 defer render.GenerateExcerptMarkdown(article) @@ -365,8 +366,8 @@ func (c *Cache) redelArticle(article *model.Article) { if serie.ID == article.SerieID { for j, v := range serie.Articles { if v == article { - Ei.Series[i].Articles = append(Ei.Series[i].Articles[0:j], - Ei.Series[i].Articles[j+1:]...) + c.Series[i].Articles = append(c.Series[i].Articles[0:j], + c.Series[i].Articles[j+1:]...) PagesCh <- PageSeries break } @@ -414,8 +415,7 @@ func (c *Cache) loadOrInit() error { Author: blogapp.Account.Username, Title: "关于", Slug: "about", - UpdatedAt: time.Now(), - CreatedAt: time.Now(), + CreatedAt: time.Time{}, } err = c.InsertArticle(context.Background(), about) if err != nil { @@ -428,8 +428,7 @@ func (c *Cache) loadOrInit() error { Author: blogapp.Account.Username, Title: "友情链接", Slug: "blogroll", - UpdatedAt: time.Now(), - CreatedAt: time.Now(), + CreatedAt: time.Time{}.AddDate(0, 0, 7), } err = c.InsertArticle(context.Background(), blogroll) if err != nil { @@ -519,7 +518,7 @@ func (c *Cache) regeneratePages() { buf.WriteString(c.Blogger.ArchivesSay + "\n") var ( currentYear string - gt12Month = len(Ei.Archives) > 12 + gt12Month = len(c.Archives) > 12 ) for _, archive := range c.Archives { t := archive.Time.In(tools.TimeLocation) diff --git a/pkg/cache/store/mongodb.go b/pkg/cache/store/mongodb.go index b94c696..f08bcb3 100644 --- a/pkg/cache/store/mongodb.go +++ b/pkg/cache/store/mongodb.go @@ -3,7 +3,6 @@ package store import ( "context" - "fmt" "sort" "time" @@ -238,7 +237,7 @@ func (db *mongodb) CleanArticles(ctx context.Context) error { collection := db.Database(mongoDBName).Collection(collectionArticle) exp := time.Now().Add(time.Duration(config.Conf.BlogApp.General.Trash) * time.Hour) - filter := bson.M{"deletetime": bson.M{"$gt": time.Time{}, "$lt": exp}} + filter := bson.M{"deleted_at": bson.M{"$gt": time.Time{}, "$lt": exp}} _, err := collection.DeleteMany(ctx, filter) return err } @@ -255,7 +254,6 @@ func (db *mongodb) UpdateArticle(ctx context.Context, id int, params[k] = v } update := bson.M{"$set": params} - fmt.Println(update) _, err := collection.UpdateOne(ctx, filter, update) return err } diff --git a/pkg/core/blog/admin/admin.go b/pkg/core/blog/admin/admin.go index a40a9bc..fa9078c 100644 --- a/pkg/core/blog/admin/admin.go +++ b/pkg/core/blog/admin/admin.go @@ -203,7 +203,7 @@ func handleAPIPostDelete(c *gin.Context) { } err = cache.Ei.DelArticle(id) if err != nil { - logrus.Error("handleAPIPostDelete.DeleteArticles: ", err) + logrus.Error("handleAPIPostDelete.DelArticle: ", err) responseNotice(c, NoticeNotice, err.Error(), "") return @@ -305,7 +305,7 @@ func handleAPIPostCreate(c *gin.Context) { article.UpdatedAt = artc.UpdatedAt } if update == "true" || update == "1" { - artc.UpdatedAt = time.Now() + article.UpdatedAt = time.Now() } // 数据库更新 err = cache.Ei.UpdateArticle(context.Background(), article.ID, map[string]interface{}{