fix: bugs

This commit is contained in:
deepzz0
2021-04-28 16:28:14 +08:00
parent 753aaa4ace
commit 4b92636079
3 changed files with 11 additions and 14 deletions
+8 -9
View File
@@ -235,7 +235,7 @@ func (c *Cache) PageArticleBE(se int, kw string, draft, del bool, p,
return nil, 0 return nil, 0
} }
max := count / n max := count / n
if max%n > 0 { if count%n > 0 {
max++ max++
} }
return articles, max return articles, max
@@ -257,11 +257,12 @@ func (c *Cache) refreshCache(article *model.Article, del bool) {
_, idx := c.FindArticleByID(article.ID) _, idx := c.FindArticleByID(article.ID)
delete(c.ArticlesMap, article.Slug) 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) c.recalcLinkedList(article, true)
// 从tag、serie、archive移除 // 从tag、serie、archive移除
c.redelArticle(article) c.redelArticle(article)
return
} }
// 添加文章 // 添加文章
defer render.GenerateExcerptMarkdown(article) defer render.GenerateExcerptMarkdown(article)
@@ -365,8 +366,8 @@ func (c *Cache) redelArticle(article *model.Article) {
if serie.ID == article.SerieID { if serie.ID == article.SerieID {
for j, v := range serie.Articles { for j, v := range serie.Articles {
if v == article { if v == article {
Ei.Series[i].Articles = append(Ei.Series[i].Articles[0:j], c.Series[i].Articles = append(c.Series[i].Articles[0:j],
Ei.Series[i].Articles[j+1:]...) c.Series[i].Articles[j+1:]...)
PagesCh <- PageSeries PagesCh <- PageSeries
break break
} }
@@ -414,8 +415,7 @@ func (c *Cache) loadOrInit() error {
Author: blogapp.Account.Username, Author: blogapp.Account.Username,
Title: "关于", Title: "关于",
Slug: "about", Slug: "about",
UpdatedAt: time.Now(), CreatedAt: time.Time{},
CreatedAt: time.Now(),
} }
err = c.InsertArticle(context.Background(), about) err = c.InsertArticle(context.Background(), about)
if err != nil { if err != nil {
@@ -428,8 +428,7 @@ func (c *Cache) loadOrInit() error {
Author: blogapp.Account.Username, Author: blogapp.Account.Username,
Title: "友情链接", Title: "友情链接",
Slug: "blogroll", Slug: "blogroll",
UpdatedAt: time.Now(), CreatedAt: time.Time{}.AddDate(0, 0, 7),
CreatedAt: time.Now(),
} }
err = c.InsertArticle(context.Background(), blogroll) err = c.InsertArticle(context.Background(), blogroll)
if err != nil { if err != nil {
@@ -519,7 +518,7 @@ func (c *Cache) regeneratePages() {
buf.WriteString(c.Blogger.ArchivesSay + "\n") buf.WriteString(c.Blogger.ArchivesSay + "\n")
var ( var (
currentYear string currentYear string
gt12Month = len(Ei.Archives) > 12 gt12Month = len(c.Archives) > 12
) )
for _, archive := range c.Archives { for _, archive := range c.Archives {
t := archive.Time.In(tools.TimeLocation) t := archive.Time.In(tools.TimeLocation)
+1 -3
View File
@@ -3,7 +3,6 @@ package store
import ( import (
"context" "context"
"fmt"
"sort" "sort"
"time" "time"
@@ -238,7 +237,7 @@ func (db *mongodb) CleanArticles(ctx context.Context) error {
collection := db.Database(mongoDBName).Collection(collectionArticle) collection := db.Database(mongoDBName).Collection(collectionArticle)
exp := time.Now().Add(time.Duration(config.Conf.BlogApp.General.Trash) * time.Hour) 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) _, err := collection.DeleteMany(ctx, filter)
return err return err
} }
@@ -255,7 +254,6 @@ func (db *mongodb) UpdateArticle(ctx context.Context, id int,
params[k] = v params[k] = v
} }
update := bson.M{"$set": params} update := bson.M{"$set": params}
fmt.Println(update)
_, err := collection.UpdateOne(ctx, filter, update) _, err := collection.UpdateOne(ctx, filter, update)
return err return err
} }
+2 -2
View File
@@ -203,7 +203,7 @@ func handleAPIPostDelete(c *gin.Context) {
} }
err = cache.Ei.DelArticle(id) err = cache.Ei.DelArticle(id)
if err != nil { if err != nil {
logrus.Error("handleAPIPostDelete.DeleteArticles: ", err) logrus.Error("handleAPIPostDelete.DelArticle: ", err)
responseNotice(c, NoticeNotice, err.Error(), "") responseNotice(c, NoticeNotice, err.Error(), "")
return return
@@ -305,7 +305,7 @@ func handleAPIPostCreate(c *gin.Context) {
article.UpdatedAt = artc.UpdatedAt article.UpdatedAt = artc.UpdatedAt
} }
if update == "true" || update == "1" { if update == "true" || update == "1" {
artc.UpdatedAt = time.Now() article.UpdatedAt = time.Now()
} }
// 数据库更新 // 数据库更新
err = cache.Ei.UpdateArticle(context.Background(), article.ID, map[string]interface{}{ err = cache.Ei.UpdateArticle(context.Background(), article.ID, map[string]interface{}{