From 6ad7472d93a54af0124efc59c82a781229fb8874 Mon Sep 17 00:00:00 2001 From: xing Date: Thu, 17 Nov 2022 17:44:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions/common/common.go | 16 ++++++++-------- config/wpconfig/term.go | 4 ++-- models/query_test.go | 2 +- models/wp/wp_terms.go | 14 +++++++------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/actions/common/common.go b/actions/common/common.go index b993426..6fb5ba7 100644 --- a/actions/common/common.go +++ b/actions/common/common.go @@ -15,7 +15,7 @@ import ( var postContextCache *cache.MapCache[uint64, PostContext] var archivesCaches *Arch -var categoryCaches *cache.SliceCache[wp.WpTermsMy] +var categoryCaches *cache.SliceCache[wp.TermsMy] var recentPostsCaches *cache.SliceCache[wp.Posts] var recentCommentsCaches *cache.SliceCache[wp.Comments] var postCommentCaches *cache.MapCache[uint64, []uint64] @@ -46,7 +46,7 @@ func InitActionsCommonCache() { postsCache = cache.NewMapCacheByBatchFn[uint64, wp.Posts](getPostsByIds, c.PostDataCacheTime) - categoryCaches = cache.NewSliceCache[wp.WpTermsMy](categories, c.CategoryCacheTime) + categoryCaches = cache.NewSliceCache[wp.TermsMy](categories, c.CategoryCacheTime) recentPostsCaches = cache.NewSliceCache[wp.Posts](recentPosts, c.RecentPostCacheTime) @@ -130,16 +130,16 @@ func Archives(ctx context.Context) (r []wp.PostArchive) { return archivesCaches.getArchiveCache(ctx) } -func Categories(ctx context.Context) []wp.WpTermsMy { +func Categories(ctx context.Context) []wp.TermsMy { r, err := categoryCaches.GetCache(ctx, time.Second, ctx) logs.ErrPrintln(err, "get category ") return r } -func categories(a ...any) (terms []wp.WpTermsMy, err error) { +func categories(a ...any) (terms []wp.TermsMy, err error) { ctx := a[0].(context.Context) var in = []any{"category"} - terms, err = models.Find[wp.WpTermsMy](ctx, models.SqlBuilder{ + terms, err = models.Find[wp.TermsMy](ctx, models.SqlBuilder{ {"tt.count", ">", "0", "int"}, {"tt.taxonomy", "in", ""}, }, "t.term_id", "", models.SqlBuilder{ @@ -148,10 +148,10 @@ func categories(a ...any) (terms []wp.WpTermsMy, err error) { {"t", "inner join", "wp_term_taxonomy tt", "t.term_id = tt.term_id"}, }, nil, 0, in) for i := 0; i < len(terms); i++ { - if v, ok := wpconfig.Terms.Load(terms[i].WpTerms.TermId); ok { - terms[i].WpTerms = v + if v, ok := wpconfig.Terms.Load(terms[i].Terms.TermId); ok { + terms[i].Terms = v } - if v, ok := wpconfig.TermTaxonomies.Load(terms[i].WpTerms.TermId); ok { + if v, ok := wpconfig.TermTaxonomies.Load(terms[i].Terms.TermId); ok { terms[i].TermTaxonomy = v } } diff --git a/config/wpconfig/term.go b/config/wpconfig/term.go index 3d20c03..e0b5a2d 100644 --- a/config/wpconfig/term.go +++ b/config/wpconfig/term.go @@ -7,12 +7,12 @@ import ( "github/fthvgb1/wp-go/safety" ) -var Terms safety.Map[uint64, wp.WpTerms] +var Terms safety.Map[uint64, wp.Terms] var TermTaxonomies safety.Map[uint64, wp.TermTaxonomy] func InitTerms() (err error) { ctx := context.Background() - terms, err := models.SimpleFind[wp.WpTerms](ctx, nil, "*") + terms, err := models.SimpleFind[wp.Terms](ctx, nil, "*") if err != nil { return err } diff --git a/models/query_test.go b/models/query_test.go index 832e6a4..50b74bd 100644 --- a/models/query_test.go +++ b/models/query_test.go @@ -153,7 +153,7 @@ func TestFind(t *testing.T) { {"a", "left join", wp.Users{}.Table() + " b", "a.post_author=b.ID"}, {"left join", "wp_term_relationships c", "a.Id=c.object_id"}, {"left join", wp.TermTaxonomy{}.Table() + " d", "c.term_taxonomy_id=d.term_taxonomy_id"}, - {"left join", wp.WpTerms{}.Table() + " e", "d.term_id=e.term_id"}, + {"left join", wp.Terms{}.Table() + " e", "d.term_id=e.term_id"}, }, having: SqlBuilder{{"n", ">", "0", "int"}}, limit: 10, diff --git a/models/wp/wp_terms.go b/models/wp/wp_terms.go index cefc8b9..8e0334b 100644 --- a/models/wp/wp_terms.go +++ b/models/wp/wp_terms.go @@ -1,27 +1,27 @@ package wp -type WpTerms struct { +type Terms struct { TermId uint64 `gorm:"column:term_id" db:"term_id" json:"term_id" form:"term_id"` Name string `gorm:"column:name" db:"name" json:"name" form:"name"` Slug string `gorm:"column:slug" db:"slug" json:"slug" form:"slug"` TermGroup int64 `gorm:"column:term_group" db:"term_group" json:"term_group" form:"term_group"` } -func (t WpTerms) PrimaryKey() string { +func (t Terms) PrimaryKey() string { return "term_id" } -func (t WpTerms) Table() string { +func (t Terms) Table() string { return "wp_terms" } -type WpTermsMy struct { - WpTerms +type TermsMy struct { + Terms TermTaxonomy } -func (t WpTermsMy) PrimaryKey() string { +func (t TermsMy) PrimaryKey() string { return "term_id" } -func (t WpTermsMy) Table() string { +func (t TermsMy) Table() string { return "wp_terms" }