小编Sai*_*hen的帖子

Gorm 需要花费大量时间从 Postgres 检索数据

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)

go go-gorm go-fiber

5
推荐指数
0
解决办法
257
查看次数

标签 统计

go ×1

go-fiber ×1

go-gorm ×1