|
@@ -98,11 +98,11 @@ func (db *clickhouse) Collection(ln model.LanguageCode, handle *string, id *stri
|
|
vars = append(vars, *handle)
|
|
vars = append(vars, *handle)
|
|
}
|
|
}
|
|
|
|
|
|
- key = productCollectionKey(clause.String(), vars...)
|
|
|
|
|
|
+ key = productCollectionKey(ln, clause.String(), vars...)
|
|
loader = func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
loader = func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
var o relation.ProductCollection
|
|
var o relation.ProductCollection
|
|
rows, err := db.session.
|
|
rows, err := db.session.
|
|
- Select(productCollectionSelection(ln)...).
|
|
|
|
|
|
+ Select(key.Selection()...).
|
|
From(key.Table()).
|
|
From(key.Table()).
|
|
Where(key.Clause(), key.Args()...).
|
|
Where(key.Clause(), key.Args()...).
|
|
Limit(1).
|
|
Limit(1).
|
|
@@ -126,12 +126,12 @@ func (db *clickhouse) Collection(ln model.LanguageCode, handle *string, id *stri
|
|
func (db *clickhouse) Collections(ln model.LanguageCode) ([]*generated.Collection, error) {
|
|
func (db *clickhouse) Collections(ln model.LanguageCode) ([]*generated.Collection, error) {
|
|
var (
|
|
var (
|
|
collections []*generated.Collection
|
|
collections []*generated.Collection
|
|
- key = productCollectionKey("list")
|
|
|
|
|
|
+ key = productCollectionKey(ln, "list")
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
var o []relation.ProductCollection
|
|
var o []relation.ProductCollection
|
|
rows, err := db.session.
|
|
rows, err := db.session.
|
|
- Select(productCollectionSelection(ln)...).
|
|
|
|
|
|
+ Select(key.Selection()...).
|
|
From(key.Table()).
|
|
From(key.Table()).
|
|
Load(&o)
|
|
Load(&o)
|
|
if rows < 1 || err != nil {
|
|
if rows < 1 || err != nil {
|
|
@@ -155,12 +155,12 @@ func (db *clickhouse) Collections(ln model.LanguageCode) ([]*generated.Collectio
|
|
func (db *clickhouse) ProductCollections(ln model.LanguageCode, id string) ([]*generated.Collection, error) {
|
|
func (db *clickhouse) ProductCollections(ln model.LanguageCode, id string) ([]*generated.Collection, error) {
|
|
var (
|
|
var (
|
|
collections []*generated.Collection
|
|
collections []*generated.Collection
|
|
- key = productCollectionKey("product.id=?", id)
|
|
|
|
|
|
+ key = productCollectionKey(ln, "product.id=?", id)
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
var o []relation.ProductCollection
|
|
var o []relation.ProductCollection
|
|
rows, err := db.session.SelectBySql("SELECT "+
|
|
rows, err := db.session.SelectBySql("SELECT "+
|
|
- strings.Join(productCollectionSelection(ln), ", ")+
|
|
|
|
|
|
+ strings.Join(key.Selection(), ", ")+
|
|
" FROM `"+key.Table()+"`"+
|
|
" FROM `"+key.Table()+"`"+
|
|
" ARRAY JOIN (SELECT `collections` FROM `product` WHERE `id` = ?) AS cid"+
|
|
" ARRAY JOIN (SELECT `collections` FROM `product` WHERE `id` = ?) AS cid"+
|
|
" WHERE `id` = cid", key.Args()...).
|
|
" WHERE `id` = cid", key.Args()...).
|
|
@@ -201,12 +201,12 @@ func (db *clickhouse) Product(ln model.LanguageCode, handle *string, id *string)
|
|
}
|
|
}
|
|
|
|
|
|
var (
|
|
var (
|
|
- key = productKey(clause.String(), vars...)
|
|
|
|
|
|
+ key = productKey(ln, defaultCurrency, clause.String(), vars...)
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
o := relation.Product{}
|
|
o := relation.Product{}
|
|
rows, err := db.session.
|
|
rows, err := db.session.
|
|
- Select(productSelection(ln, defaultCurrency)...).
|
|
|
|
|
|
+ Select(key.Selection()...).
|
|
From(fmt.Sprintf("%s as t", key.Table())).
|
|
From(fmt.Sprintf("%s as t", key.Table())).
|
|
LeftJoin("product_variant", "product_variant.product_id = t.id").
|
|
LeftJoin("product_variant", "product_variant.product_id = t.id").
|
|
LeftJoin("inventory_item", "inventory_item.id = product_variant.inventory_item_id").
|
|
LeftJoin("inventory_item", "inventory_item.id = product_variant.inventory_item_id").
|
|
@@ -235,12 +235,12 @@ func (db *clickhouse) Product(ln model.LanguageCode, handle *string, id *string)
|
|
func (db *clickhouse) ProductOptions(ln model.LanguageCode, id string) ([]*generated.ProductOption, error) {
|
|
func (db *clickhouse) ProductOptions(ln model.LanguageCode, id string) ([]*generated.ProductOption, error) {
|
|
var (
|
|
var (
|
|
options []*generated.ProductOption
|
|
options []*generated.ProductOption
|
|
- key = productOptionKey("product_id=?", id)
|
|
|
|
|
|
+ key = productOptionKey(ln, "product_id=?", id)
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
var o []relation.ProductOption
|
|
var o []relation.ProductOption
|
|
rows, err := db.session.SelectBySql("SELECT "+
|
|
rows, err := db.session.SelectBySql("SELECT "+
|
|
- strings.Join(productOptionSelection(ln), ", ")+
|
|
|
|
|
|
+ strings.Join(key.Selection(), ", ")+
|
|
" FROM `"+key.Table()+"`"+
|
|
" FROM `"+key.Table()+"`"+
|
|
" ARRAY JOIN (SELECT `options` FROM `product` WHERE `id` = ?) AS oid"+
|
|
" ARRAY JOIN (SELECT `options` FROM `product` WHERE `id` = ?) AS oid"+
|
|
" WHERE `id` = oid", key.Args()).
|
|
" WHERE `id` = oid", key.Args()).
|
|
@@ -266,12 +266,12 @@ func (db *clickhouse) ProductOptions(ln model.LanguageCode, id string) ([]*gener
|
|
func (db *clickhouse) ProductVariants(ctx *middleware.GShopifyContext, id string) ([]*generated.ProductVariant, error) {
|
|
func (db *clickhouse) ProductVariants(ctx *middleware.GShopifyContext, id string) ([]*generated.ProductVariant, error) {
|
|
var (
|
|
var (
|
|
variants []*generated.ProductVariant
|
|
variants []*generated.ProductVariant
|
|
- key = productVariantKey("t.product_id=?", id)
|
|
|
|
|
|
+ key = productVariantKey(ctx.Language, defaultCurrency, "t.product_id=?", id)
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
var o []relation.ProductVariant
|
|
var o []relation.ProductVariant
|
|
rows, err := db.session.
|
|
rows, err := db.session.
|
|
- Select(productVariantSelection(ctx.Language, defaultCurrency)...).
|
|
|
|
|
|
+ Select(key.Selection()...).
|
|
From(fmt.Sprintf("%s as t", key.Table())).
|
|
From(fmt.Sprintf("%s as t", key.Table())).
|
|
LeftJoin("product", "product.id = t.product_id").
|
|
LeftJoin("product", "product.id = t.product_id").
|
|
LeftJoin("inventory_item", "inventory_item.id = t.inventory_item_id").
|
|
LeftJoin("inventory_item", "inventory_item.id = t.inventory_item_id").
|
|
@@ -302,12 +302,12 @@ func (db *clickhouse) ProductVariants(ctx *middleware.GShopifyContext, id string
|
|
func (db *clickhouse) CollectionProducts(ln model.LanguageCode, id string) ([]*generated.Product, error) {
|
|
func (db *clickhouse) CollectionProducts(ln model.LanguageCode, id string) ([]*generated.Product, error) {
|
|
var (
|
|
var (
|
|
products []*generated.Product
|
|
products []*generated.Product
|
|
- key = productKey("has(t.collections, ?) AND t.status = ?", id, model.ProductStatusActive)
|
|
|
|
|
|
+ key = productKey(ln, defaultCurrency, "has(t.collections, ?) AND t.status = ?", id, model.ProductStatusActive)
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
var o []relation.Product
|
|
var o []relation.Product
|
|
rows, err := db.session.
|
|
rows, err := db.session.
|
|
- Select(productSelection(ln, defaultCurrency)...).
|
|
|
|
|
|
+ Select(key.Selection()...).
|
|
From(fmt.Sprintf("%s as t", key.Table())).
|
|
From(fmt.Sprintf("%s as t", key.Table())).
|
|
LeftJoin("product_variant", "product_variant.product_id = t.id").
|
|
LeftJoin("product_variant", "product_variant.product_id = t.id").
|
|
LeftJoin("inventory_item", "inventory_item.id = product_variant.inventory_item_id").
|
|
LeftJoin("inventory_item", "inventory_item.id = product_variant.inventory_item_id").
|
|
@@ -339,14 +339,14 @@ func (db *clickhouse) CollectionProducts(ln model.LanguageCode, id string) ([]*g
|
|
func (db *clickhouse) ProductVariantOptions(ln model.LanguageCode, id string) ([]*generated.SelectedOption, error) {
|
|
func (db *clickhouse) ProductVariantOptions(ln model.LanguageCode, id string) ([]*generated.SelectedOption, error) {
|
|
var (
|
|
var (
|
|
options []*generated.SelectedOption
|
|
options []*generated.SelectedOption
|
|
- key = productOptionKey("product_variant.id = ?", id)
|
|
|
|
|
|
+ key = productOptionKey(ln, "product_variant.id = ?", id)
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
l = ttlcache.LoaderFunc[string, any](
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
func(ttl *ttlcache.Cache[string, any], _ string) *ttlcache.Item[string, any] {
|
|
var o []relation.ProductOption
|
|
var o []relation.ProductOption
|
|
rows, err := db.session.SelectBySql("SELECT "+
|
|
rows, err := db.session.SelectBySql("SELECT "+
|
|
- strings.Join(productOptionSelectedSelection(ln), ", ")+
|
|
|
|
|
|
+ strings.Join(key.Selection(), ", ")+
|
|
" FROM `"+key.Table()+"`"+
|
|
" FROM `"+key.Table()+"`"+
|
|
- " ARRAY JOIN (SELECT `options` from `product_variant` where `id` = ?) as opt"+
|
|
|
|
|
|
+ " ARRAY JOIN (SELECT anyLast(options) as options from `product_variant` where `id` = ? GROUP BY id) as opt"+
|
|
" WHERE id = tupleElement(opt, 1)"+
|
|
" WHERE id = tupleElement(opt, 1)"+
|
|
" ORDER BY position", key.Args()).
|
|
" ORDER BY position", key.Args()).
|
|
Load(&o)
|
|
Load(&o)
|