Mhamdans17 commited on
Commit ·
4ffd896
1
Parent(s): 44f1ca9
perf: completely avoid SELECT * in CreateProduct and UpdateProduct by selecting Category directly instead of First product load
Browse files
controllers/product_controller.go
CHANGED
|
@@ -407,8 +407,9 @@ func CreateProduct(c *gin.Context) {
|
|
| 407 |
return
|
| 408 |
}
|
| 409 |
|
| 410 |
-
|
| 411 |
-
|
|
|
|
| 412 |
|
| 413 |
c.JSON(http.StatusCreated, newProduct)
|
| 414 |
}
|
|
@@ -470,7 +471,9 @@ func UpdateProduct(c *gin.Context) {
|
|
| 470 |
return
|
| 471 |
}
|
| 472 |
|
| 473 |
-
|
|
|
|
|
|
|
| 474 |
|
| 475 |
c.JSON(http.StatusOK, product)
|
| 476 |
}
|
|
|
|
| 407 |
return
|
| 408 |
}
|
| 409 |
|
| 410 |
+
if newProduct.CategoryID != nil {
|
| 411 |
+
config.DB.Select("id, name").First(&newProduct.Category, *newProduct.CategoryID)
|
| 412 |
+
}
|
| 413 |
|
| 414 |
c.JSON(http.StatusCreated, newProduct)
|
| 415 |
}
|
|
|
|
| 471 |
return
|
| 472 |
}
|
| 473 |
|
| 474 |
+
if product.CategoryID != nil {
|
| 475 |
+
config.DB.Select("id, name").First(&product.Category, *product.CategoryID)
|
| 476 |
+
}
|
| 477 |
|
| 478 |
c.JSON(http.StatusOK, product)
|
| 479 |
}
|