2022-11-17 08:29:39 +00:00
|
|
|
package wpconfig
|
2022-11-15 03:11:08 +00:00
|
|
|
|
|
|
|
import (
|
2023-01-18 15:02:59 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
|
|
|
"github.com/fthvgb1/wp-go/model"
|
|
|
|
"github.com/fthvgb1/wp-go/safety"
|
2022-11-15 03:11:08 +00:00
|
|
|
)
|
|
|
|
|
2023-04-15 16:57:50 +00:00
|
|
|
var terms = safety.NewMap[uint64, models.Terms]()
|
|
|
|
var termTaxonomies = safety.NewMap[uint64, models.TermTaxonomy]()
|
|
|
|
|
|
|
|
var my = safety.NewMap[uint64, models.TermsMy]()
|
|
|
|
|
|
|
|
func GetTerm(termId uint64) (models.Terms, bool) {
|
|
|
|
return terms.Load(termId)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetTermTaxonomy(termId uint64) (models.TermTaxonomy, bool) {
|
|
|
|
return termTaxonomies.Load(termId)
|
|
|
|
}
|
|
|
|
func GetTermMy(termId uint64) (models.TermsMy, bool) {
|
|
|
|
return my.Load(termId)
|
|
|
|
}
|
2022-11-15 03:11:08 +00:00
|
|
|
|
|
|
|
func InitTerms() (err error) {
|
2023-04-15 16:57:50 +00:00
|
|
|
terms.Flush()
|
|
|
|
termTaxonomies.Flush()
|
|
|
|
term, err := model.SimpleFind[models.Terms](ctx, nil, "*")
|
2022-11-15 03:11:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-04-15 16:57:50 +00:00
|
|
|
for _, wpTerms := range term {
|
|
|
|
terms.Store(wpTerms.TermId, wpTerms)
|
2022-11-15 03:11:08 +00:00
|
|
|
}
|
2023-01-13 06:04:32 +00:00
|
|
|
termTax, err := model.SimpleFind[models.TermTaxonomy](ctx, nil, "*")
|
2022-11-15 03:11:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, taxonomy := range termTax {
|
2023-04-15 16:57:50 +00:00
|
|
|
termTaxonomies.Store(taxonomy.TermTaxonomyId, taxonomy)
|
|
|
|
if term, ok := terms.Load(taxonomy.TermId); ok {
|
|
|
|
my.Store(taxonomy.TermId, models.TermsMy{
|
|
|
|
Terms: term,
|
|
|
|
TermTaxonomy: taxonomy,
|
|
|
|
})
|
|
|
|
}
|
2022-11-15 03:11:08 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|