|
@@ -299,10 +299,23 @@ func (db *clickhouse) ProductVariants(ctx *middleware.GShopifyContext, id string
|
|
|
return variants, nil
|
|
|
}
|
|
|
|
|
|
-func (db *clickhouse) CollectionProducts(ln model.LanguageCode, id string) ([]*generated.Product, error) {
|
|
|
+func (db *clickhouse) Products(ln model.LanguageCode, collectionId *string) ([]*generated.Product, error) {
|
|
|
+ var (
|
|
|
+ clause = strings.Builder{}
|
|
|
+ args []any
|
|
|
+ )
|
|
|
+
|
|
|
+ clause.WriteString("t.status = ?")
|
|
|
+ args = append(args, model.ProductStatusActive)
|
|
|
+
|
|
|
+ if collectionId != nil {
|
|
|
+ clause.WriteString(" AND has(t.collections, ?)")
|
|
|
+ args = append(args, *collectionId)
|
|
|
+ }
|
|
|
+
|
|
|
var (
|
|
|
products []*generated.Product
|
|
|
- key = productKey(ln, defaultCurrency, "has(t.collections, ?) AND t.status = ?", id, model.ProductStatusActive)
|
|
|
+ key = productKey(ln, defaultCurrency, clause.String(), args...)
|
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
|
var o []relation.Product
|
|
@@ -324,13 +337,10 @@ func (db *clickhouse) CollectionProducts(ln model.LanguageCode, id string) ([]*g
|
|
|
)
|
|
|
)
|
|
|
|
|
|
- p := db.cache.Get(key.String(), ttlcache.WithLoader[string, any](l))
|
|
|
- if p == nil {
|
|
|
- return nil, fmt.Errorf("not found")
|
|
|
- }
|
|
|
-
|
|
|
- for _, row := range p.Value().([]relation.Product) {
|
|
|
- products = append(products, row.As())
|
|
|
+ if p := db.cache.Get(key.String(), ttlcache.WithLoader[string, any](l)); p != nil {
|
|
|
+ for _, row := range p.Value().([]relation.Product) {
|
|
|
+ products = append(products, row.As())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return products, nil
|