|
@@ -378,13 +378,13 @@ func (db *clickhouse) ProductVariantOptions(ln model.LanguageCode, id string) ([
|
|
|
return options, nil
|
|
|
}
|
|
|
|
|
|
-func (db *clickhouse) ProductTags() ([]model.ProductTag, error) {
|
|
|
+func (db *clickhouse) ProductTags() ([]*model.ProductTag, error) {
|
|
|
var (
|
|
|
- tags []model.ProductTag
|
|
|
+ tags []*model.ProductTag
|
|
|
key = productTagKey("list")
|
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
|
- var o []model.ProductTag
|
|
|
+ var o []*model.ProductTag
|
|
|
rows, err := db.session.
|
|
|
Select(key.Selection()...).
|
|
|
From(key.Table()).
|
|
@@ -400,7 +400,7 @@ func (db *clickhouse) ProductTags() ([]model.ProductTag, error) {
|
|
|
)
|
|
|
|
|
|
if p := db.cache.Get(key.String(), ttlcache.WithLoader[string, any](l)); p != nil {
|
|
|
- for _, s := range p.Value().([]model.ProductTag) {
|
|
|
+ for _, s := range p.Value().([]*model.ProductTag) {
|
|
|
tags = append(tags, s)
|
|
|
}
|
|
|
}
|
|
@@ -408,6 +408,36 @@ func (db *clickhouse) ProductTags() ([]model.ProductTag, error) {
|
|
|
return tags, nil
|
|
|
}
|
|
|
|
|
|
+func (db *clickhouse) ProductTypes() ([]*model.ProductType, error) {
|
|
|
+ var (
|
|
|
+ types []*model.ProductType
|
|
|
+ key = productTypeKey("list")
|
|
|
+ l = ttlcache.LoaderFunc[string, any](
|
|
|
+ func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
|
+ var o []*model.ProductType
|
|
|
+ rows, err := db.session.
|
|
|
+ Select(key.Selection()...).
|
|
|
+ From(key.Table()).
|
|
|
+ OrderBy("count DESC").
|
|
|
+ Load(&o)
|
|
|
+ if rows < 1 || err != nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ return ttl.Set(key.String(), o, key.TTL())
|
|
|
+ },
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ if p := db.cache.Get(key.String(), ttlcache.WithLoader[string, any](l)); p != nil {
|
|
|
+ for _, s := range p.Value().([]*model.ProductType) {
|
|
|
+ types = append(types, s)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return types, nil
|
|
|
+}
|
|
|
+
|
|
|
func (db *clickhouse) Ping() error {
|
|
|
return db.session.Ping()
|
|
|
}
|