23:28:45 | 200 | 20.294s | 127.0.0.1 | GET | /api/user/cart/product/all
Run Code Online (Sandbox Code Playgroud)
从购物车产品中,我检索带有购物车产品的购物车。尽管购物车只有一辆购物车和一种产品。但检索起来需要太多时间。
var cart model.Cart
if err := model.DB.Select([]string{"id"}).Preload("CartProduct", func(db *gorm.DB) *gorm.DB {
return db.Select([]string{"cart_id", "id", "quantity", "seller_product_id", "seller_product_variation_id"})
}).Preload("CartProduct.SellerProduct", func(db *gorm.DB) *gorm.DB {
return db.Select([]string{"id", "name", "slug", "selling_price", "product_price", "offer_price", "offer_price_start", "offer_price_end", "quantity", "next_stock", "description"})
}).Preload("CartProduct.SellerProduct.SellerProductImage", func(db *gorm.DB) *gorm.DB {
return db.Select([]string{"image", "seller_product_id"}).Where("display = ?", true)
}).Preload("CartProduct.SellerProductVariation", func(db *gorm.DB) *gorm.DB {
return db.Select([]string{"id", "image", "product_price", "selling_price", "quantity", "seller_product_id"})
}).Preload("CartProduct.SellerProductVariation.SellerProductVariationValues", func(db *gorm.DB) *gorm.DB {
return db.Select([]string{"id", "name", "description", "attribute_id", "seller_product_variation_id"}) …Run Code Online (Sandbox Code Playgroud)