|
@@ -81,18 +81,12 @@ func (db *clickhouse) ProductCollections(ln model.LanguageCode, id string) ([]*g
|
|
|
key = productCollectionKey("product.id=?", id)
|
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
|
- var o []relation.Collection
|
|
|
-
|
|
|
+ var o []relation.ProductCollection
|
|
|
rows, err := db.session.SelectBySql("SELECT "+
|
|
|
- ln.SqlFieldSelection("title", "")+
|
|
|
- ", "+
|
|
|
- ln.SqlFieldSelection("description", "")+
|
|
|
- ", `id`, `handle`, `thumbnail`, "+
|
|
|
- "`created_at`, `updated_at`, `deleted_at` "+
|
|
|
- "FROM `product_collection` "+
|
|
|
- "ARRAY JOIN (SELECT `collection_ids` FROM `product` WHERE `id` = ?) AS cid "+
|
|
|
- "WHERE `id` = cid "+
|
|
|
- "ORDER BY `created_at` ASC;", key.Args()...).
|
|
|
+ strings.Join(productCollectionSelection(ln), ", ")+
|
|
|
+ " FROM `"+key.Table()+"`"+
|
|
|
+ " ARRAY JOIN (SELECT `collections` FROM `product` WHERE `id` = ?) AS cid"+
|
|
|
+ " WHERE `id` = cid", key.Args()...).
|
|
|
Load(&o)
|
|
|
if rows < 1 || err != nil {
|
|
|
return nil
|
|
@@ -102,13 +96,10 @@ func (db *clickhouse) ProductCollections(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.Collection) {
|
|
|
- collections = append(collections, row.As())
|
|
|
+ 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
|
|
@@ -117,7 +108,7 @@ func (db *clickhouse) ProductCollections(ln model.LanguageCode, id string) ([]*g
|
|
|
func (db *clickhouse) Product(ln model.LanguageCode, handle *string, id *string) (*generated.Product, error) {
|
|
|
var (
|
|
|
clause = strings.Builder{}
|
|
|
- vars = []any{relation.ProductStatusPublished}
|
|
|
+ vars = []any{model.ProductStatusActive}
|
|
|
)
|
|
|
|
|
|
clause.WriteString("status=?")
|
|
@@ -141,7 +132,6 @@ func (db *clickhouse) Product(ln model.LanguageCode, handle *string, id *string)
|
|
|
Select(productSelection(ln)...).
|
|
|
From(key.Table()).
|
|
|
Where(key.Clause(), key.Args()...).
|
|
|
- OrderBy("created_at").
|
|
|
Limit(1).
|
|
|
Load(&o)
|
|
|
if rows < 1 || err != nil {
|
|
@@ -168,11 +158,11 @@ func (db *clickhouse) ProductOptions(ln model.LanguageCode, id string) ([]*gener
|
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
|
var o []relation.ProductOption
|
|
|
- rows, err := db.session.
|
|
|
- Select(productOptionSelection(ln)...).
|
|
|
- From(key.Table()).
|
|
|
- Where(key.Clause(), key.Args()...).
|
|
|
- OrderBy("created_at").
|
|
|
+ rows, err := db.session.SelectBySql("SELECT "+
|
|
|
+ strings.Join(productOptionSelection(ln), ", ")+
|
|
|
+ " FROM `"+key.Table()+"`"+
|
|
|
+ " ARRAY JOIN (SELECT `options` FROM `product` WHERE `id` = ?) AS oid"+
|
|
|
+ " WHERE `id` = oid", key.Args()).
|
|
|
Load(&o)
|
|
|
if rows < 1 || err != nil {
|
|
|
return nil
|
|
@@ -183,13 +173,10 @@ func (db *clickhouse) ProductOptions(ln model.LanguageCode, id string) ([]*gener
|
|
|
)
|
|
|
)
|
|
|
|
|
|
- p := db.cache.Get(key.String(), ttlcache.WithLoader[string, any](l))
|
|
|
- if p == nil {
|
|
|
- return nil, fmt.Errorf("not found")
|
|
|
- }
|
|
|
-
|
|
|
- for _, v := range p.Value().([]relation.ProductOption) {
|
|
|
- options = append(options, v.As())
|
|
|
+ if p := db.cache.Get(key.String(), ttlcache.WithLoader[string, any](l)); p != nil {
|
|
|
+ for _, v := range p.Value().([]relation.ProductOption) {
|
|
|
+ options = append(options, v.As())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return options, nil
|
|
@@ -243,7 +230,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(collection_ids, ?)", id)
|
|
|
+ key = productKey("has(collections, ?)", id)
|
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
|
var o []relation.Product
|
|
@@ -251,7 +238,6 @@ func (db *clickhouse) CollectionProducts(ln model.LanguageCode, id string) ([]*g
|
|
|
Select(productSelection(ln)...).
|
|
|
From(key.Table()).
|
|
|
Where(key.Clause(), key.Args()...).
|
|
|
- OrderBy("created_at").
|
|
|
Load(&o)
|
|
|
if rows < 1 || err != nil {
|
|
|
return nil
|