From 80d84f64aa2afd59470ec56423912239f1bb2840 Mon Sep 17 00:00:00 2001 From: merdan Date: Fri, 16 Sep 2022 20:22:57 +0500 Subject: [PATCH] delete fix --- gorm_models/product.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gorm_models/product.go b/gorm_models/product.go index b79b409..9ae0825 100644 --- a/gorm_models/product.go +++ b/gorm_models/product.go @@ -95,9 +95,10 @@ func (ProductFlat) TableName() string { func DeleteProducts(db *gorm.DB) error { //todo delete from elastico - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute) defer cancel() - qb := "DELETE p.* FROM products p, order_items oi WHERE p.id NOT IN (select product_id from wishlist) AND p.id NOT IN (select product_id from order_items) AND p.id NOT IN (select parent_id from order_items)" + //qb := "DELETE FROM products WHERE id NOT IN (select product_id as id from wishlist) AND id NOT IN (select product_id as id from order_items) AND id NOT IN (select parent_id as idfrom order_items);" + qb := "DELETE p FROM products p LEFT JOIN wishlist w on p.id = w.product_id LEFT JOIN order_items oi ON p.id = oi.product_id LEFT JOIN order_items op ON p.id = op.parent_id WHERE w.id IS NULL AND oi.id IS NULL AND op.id IS NULL;" return db.WithContext(ctx).Exec(qb).Error }