2022-11-17 08:29:39 +00:00
|
|
|
package wpconfig
|
2022-11-15 03:11:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
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-01-13 06:04:32 +00:00
|
|
|
var Terms safety.Map[uint64, models.Terms]
|
|
|
|
var TermTaxonomies safety.Map[uint64, models.TermTaxonomy]
|
2022-11-15 03:11:08 +00:00
|
|
|
|
|
|
|
func InitTerms() (err error) {
|
|
|
|
ctx := context.Background()
|
2023-01-13 06:04:32 +00:00
|
|
|
terms, err := model.SimpleFind[models.Terms](ctx, nil, "*")
|
2022-11-15 03:11:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, wpTerms := range terms {
|
|
|
|
Terms.Store(wpTerms.TermId, wpTerms)
|
|
|
|
}
|
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 {
|
|
|
|
TermTaxonomies.Store(taxonomy.TermTaxonomyId, taxonomy)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|