seller id deadlock and delete elapsed time

This commit is contained in:
merdan 2022-09-21 14:47:58 +05:00
parent 190306d902
commit 3693589d66
2 changed files with 7 additions and 3 deletions

View File

@ -592,11 +592,15 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
}
errFlat := db.Omit("ParentID", "CreatedAt", "Variants").Save(&mainProductFlat)
var errFlat error
if mainProductFlat.SpecialPrice != 0 {
errFlat = db.Omit("ParentID", "CreatedAt", "Variants").Save(&mainProductFlat).Error
} else {
errFlat = db.Omit("ParentID", "CreatedAt", "Variants", "SpecialPrice").Save(&mainProductFlat).Error
}
if errFlat != nil {
log.Println(errFlat)
}
sProduct := createSellerProduct(&mainProductFlat, product.Vendor)

View File

@ -98,7 +98,7 @@ func DeleteProducts(db *gorm.DB) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
//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;"
qb := "DELETE p FROM products p LEFT JOIN order_items oi ON p.id = oi.product_id LEFT JOIN order_items op ON p.id = op.parent_id WHERE oi.id IS NULL AND op.id IS NULL;"
return db.WithContext(ctx).Exec(qb).Error
}