|
@@ -75,6 +75,35 @@ func New(ctx context.Context, forceDebug bool) (Database, error) {
|
|
|
return r, nil
|
|
|
}
|
|
|
|
|
|
+func (db *clickhouse) Collections(ln model.LanguageCode) ([]*generated.Collection, error) {
|
|
|
+ var (
|
|
|
+ collections []*generated.Collection
|
|
|
+ key = productCollectionKey("list")
|
|
|
+ l = ttlcache.LoaderFunc[string, any](
|
|
|
+ func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
|
+ var o []relation.ProductCollection
|
|
|
+ rows, err := db.session.
|
|
|
+ Select(productCollectionSelection(ln)...).
|
|
|
+ From(key.Table()).
|
|
|
+ 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 _, row := range p.Value().([]relation.ProductCollection) {
|
|
|
+ collections = append(collections, row.As())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return collections, nil
|
|
|
+}
|
|
|
+
|
|
|
func (db *clickhouse) ProductCollections(ln model.LanguageCode, id string) ([]*generated.Collection, error) {
|
|
|
var (
|
|
|
collections []*generated.Collection
|
|
@@ -225,7 +254,7 @@ func (db *clickhouse) ProductVariants(ctx *middleware.GShopifyContext, id string
|
|
|
func (db *clickhouse) CollectionProducts(ln model.LanguageCode, id string) ([]*generated.Product, error) {
|
|
|
var (
|
|
|
products []*generated.Product
|
|
|
- key = productKey("has(t.collections, ?)", id)
|
|
|
+ key = productKey("has(t.collections, ?) AND t.status = ?", id, model.ProductStatusActive)
|
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
|
var o []relation.Product
|