优化
This commit is contained in:
parent
8752d4a023
commit
6ad7472d93
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user