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

17
pkg/cache/cache.go vendored
View File

@@ -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)

View File

@@ -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
}

View File

@@ -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{}{