|
@@ -378,6 +378,36 @@ func (db *clickhouse) ProductVariantOptions(ln model.LanguageCode, id string) ([
|
|
|
return options, nil
|
|
|
}
|
|
|
|
|
|
+func (db *clickhouse) ProductTags() ([]model.ProductTag, error) {
|
|
|
+ var (
|
|
|
+ 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
|
|
|
+ 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.ProductTag) {
|
|
|
+ tags = append(tags, s)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return tags, nil
|
|
|
+}
|
|
|
+
|
|
|
func (db *clickhouse) Ping() error {
|
|
|
return db.session.Ping()
|
|
|
}
|