diff --git a/actions/comment.go b/actions/comment.go index 8458af9..dc955e6 100644 --- a/actions/comment.go +++ b/actions/comment.go @@ -68,7 +68,7 @@ func PostComment(c *gin.Context) { logs.ErrPrintln(err, "获取文档", id) return } - su := fmt.Sprintf("%s: %s[%s]发表了评论对文档[%v]的评论", wp.Options["siteurl"], author, m, post.PostTitle) + su := fmt.Sprintf("%s: %s[%s]发表了评论对文档[%v]的评论", wp.Option["siteurl"], author, m, post.PostTitle) err = mail.SendMail([]string{config.Conf.Mail.User}, su, comment) logs.ErrPrintln(err, "发送邮件") }() diff --git a/actions/common/comments.go b/actions/common/comments.go index 6998b40..7c3dfbd 100644 --- a/actions/common/comments.go +++ b/actions/common/comments.go @@ -10,7 +10,7 @@ import ( "time" ) -func RecentComments(ctx context.Context, n int) (r []wp.WpComments) { +func RecentComments(ctx context.Context, n int) (r []wp.Comments) { r, err := recentCommentsCaches.GetCache(ctx, time.Second) if len(r) > n { r = r[0:n] @@ -18,8 +18,8 @@ func RecentComments(ctx context.Context, n int) (r []wp.WpComments) { logs.ErrPrintln(err, "get recent comment") return } -func recentComments(...any) (r []wp.WpComments, err error) { - return models.Find[wp.WpComments](models.SqlBuilder{ +func recentComments(...any) (r []wp.Comments, err error) { + return models.Find[wp.Comments](models.SqlBuilder{ {"comment_approved", "1"}, {"post_status", "publish"}, }, "comment_ID,comment_author,comment_post_ID,post_title", "", models.SqlBuilder{{"comment_date_gmt", "desc"}}, models.SqlBuilder{ @@ -27,7 +27,7 @@ func recentComments(...any) (r []wp.WpComments, err error) { }, nil, 10) } -func PostComments(ctx context.Context, Id uint64) ([]wp.WpComments, error) { +func PostComments(ctx context.Context, Id uint64) ([]wp.Comments, error) { ids, err := postCommentCaches.GetCache(ctx, Id, time.Second, Id) if err != nil { return nil, err @@ -37,7 +37,7 @@ func PostComments(ctx context.Context, Id uint64) ([]wp.WpComments, error) { func postComments(args ...any) ([]uint64, error) { postId := args[0].(uint64) - r, err := models.Find[wp.WpComments](models.SqlBuilder{ + r, err := models.Find[wp.Comments](models.SqlBuilder{ {"comment_approved", "1"}, {"comment_post_ID", "=", strconv.FormatUint(postId, 10), "int"}, }, "comment_ID", "", models.SqlBuilder{ @@ -47,29 +47,29 @@ func postComments(args ...any) ([]uint64, error) { if err != nil { return nil, err } - return helper.SliceMap(r, func(t wp.WpComments) uint64 { + return helper.SliceMap(r, func(t wp.Comments) uint64 { return t.CommentId }), err } -func GetCommentById(ctx context.Context, id uint64) (wp.WpComments, error) { +func GetCommentById(ctx context.Context, id uint64) (wp.Comments, error) { return commentsCache.GetCache(ctx, id, time.Second, id) } -func GetCommentByIds(ctx context.Context, ids []uint64) ([]wp.WpComments, error) { +func GetCommentByIds(ctx context.Context, ids []uint64) ([]wp.Comments, error) { return commentsCache.GetCacheBatch(ctx, ids, time.Second, ids) } -func getCommentByIds(args ...any) (map[uint64]wp.WpComments, error) { +func getCommentByIds(args ...any) (map[uint64]wp.Comments, error) { ids := args[0].([]uint64) - m := make(map[uint64]wp.WpComments) - r, err := models.SimpleFind[wp.WpComments](models.SqlBuilder{ + m := make(map[uint64]wp.Comments) + r, err := models.SimpleFind[wp.Comments](models.SqlBuilder{ {"comment_ID", "in", ""}, {"comment_approved", "1"}, }, "*", helper.SliceMap(ids, helper.ToAny[uint64])) if err != nil { return m, err } - return helper.SimpleSliceToMap(r, func(t wp.WpComments) uint64 { + return helper.SimpleSliceToMap(r, func(t wp.Comments) uint64 { return t.CommentId }), err } diff --git a/actions/common/common.go b/actions/common/common.go index fe3ee9f..0d9d981 100644 --- a/actions/common/common.go +++ b/actions/common/common.go @@ -15,17 +15,17 @@ import ( var postContextCache *cache.MapCache[uint64, PostContext] var archivesCaches *Arch var categoryCaches *cache.SliceCache[wp.WpTermsMy] -var recentPostsCaches *cache.SliceCache[wp.WpPosts] -var recentCommentsCaches *cache.SliceCache[wp.WpComments] +var recentPostsCaches *cache.SliceCache[wp.Posts] +var recentCommentsCaches *cache.SliceCache[wp.Comments] var postCommentCaches *cache.MapCache[uint64, []uint64] -var postsCache *cache.MapCache[uint64, wp.WpPosts] +var postsCache *cache.MapCache[uint64, wp.Posts] var monthPostsCache *cache.MapCache[string, []uint64] var postListIdsCache *cache.MapCache[string, PostIds] var searchPostIdsCache *cache.MapCache[string, PostIds] var maxPostIdCache *cache.SliceCache[uint64] var TotalRaw int -var usersCache *cache.MapCache[uint64, wp.WpUsers] -var commentsCache *cache.MapCache[uint64, wp.WpComments] +var usersCache *cache.MapCache[uint64, wp.Users] +var commentsCache *cache.MapCache[uint64, wp.Comments] func InitActionsCommonCache() { archivesCaches = &Arch{ @@ -41,21 +41,21 @@ func InitActionsCommonCache() { postContextCache = cache.NewMapCacheByFn[uint64, PostContext](getPostContext, config.Conf.ContextPostCacheTime) - postsCache = cache.NewMapCacheByBatchFn[uint64, wp.WpPosts](getPostsByIds, config.Conf.PostDataCacheTime) + postsCache = cache.NewMapCacheByBatchFn[uint64, wp.Posts](getPostsByIds, config.Conf.PostDataCacheTime) categoryCaches = cache.NewSliceCache[wp.WpTermsMy](categories, config.Conf.CategoryCacheTime) - recentPostsCaches = cache.NewSliceCache[wp.WpPosts](recentPosts, config.Conf.RecentPostCacheTime) + recentPostsCaches = cache.NewSliceCache[wp.Posts](recentPosts, config.Conf.RecentPostCacheTime) - recentCommentsCaches = cache.NewSliceCache[wp.WpComments](recentComments, config.Conf.RecentCommentsCacheTime) + recentCommentsCaches = cache.NewSliceCache[wp.Comments](recentComments, config.Conf.RecentCommentsCacheTime) postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](postComments, config.Conf.PostCommentsCacheTime) maxPostIdCache = cache.NewSliceCache[uint64](getMaxPostId, config.Conf.MaxPostIdCacheTime) - usersCache = cache.NewMapCacheByBatchFn[uint64, wp.WpUsers](getUsers, config.Conf.UserInfoCacheTime) + usersCache = cache.NewMapCacheByBatchFn[uint64, wp.Users](getUsers, config.Conf.UserInfoCacheTime) - commentsCache = cache.NewMapCacheByBatchFn[uint64, wp.WpComments](getCommentByIds, config.Conf.CommentsCacheTime) + commentsCache = cache.NewMapCacheByBatchFn[uint64, wp.Comments](getCommentByIds, config.Conf.CommentsCacheTime) } func ClearCache() { @@ -99,8 +99,8 @@ func (c *Arch) getArchiveCache() []wp.PostArchive { } type PostContext struct { - prev wp.WpPosts - next wp.WpPosts + prev wp.Posts + next wp.Posts } func archives() ([]wp.PostArchive, error) { @@ -133,20 +133,20 @@ func categories(...any) (terms []wp.WpTermsMy, err error) { if v, ok := wp.Terms[terms[i].WpTerms.TermId]; ok { terms[i].WpTerms = v } - if v, ok := wp.TermTaxonomy[terms[i].WpTerms.TermId]; ok { - terms[i].WpTermTaxonomy = v + if v, ok := wp.TermTaxonomies[terms[i].WpTerms.TermId]; ok { + terms[i].TermTaxonomy = v } } return } -func PasswordProjectTitle(post *wp.WpPosts) { +func PasswordProjectTitle(post *wp.Posts) { if post.PostPassword != "" { post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle) } } -func PasswdProjectContent(post *wp.WpPosts) { +func PasswdProjectContent(post *wp.Posts) { if post.PostContent != "" { format := `