Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1168 storefront only get product added to warehouse #1246

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

DinhThaiVV
Copy link
Contributor

Issue #1168

Copy link

github-actions bot commented Oct 30, 2024

Inventory Coverage Report

Overall Project 90.05% -0.51% 🍏
Files changed 0%

File Coverage
StockService.java 97.69% -1.54%
StockController.java 84.62% -15.38%

Copy link

sonarcloud bot commented Oct 30, 2024

Copy link

sonarcloud bot commented Oct 30, 2024

Copy link

sonarcloud bot commented Oct 30, 2024

Copy link

Product Coverage Report

Overall Project 77.6% -0.43%
Files changed 25.53%

File Coverage
ProductService.java 77.55% -0.1% 🍏
InventoryService.java 0%

Copy link
Contributor

@minhtridn2001 minhtridn2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @DinhThaiVV,
Kindly check my comments. There are a few points that may need discussion. Let me know if you have any inquiries.
Thanks!

Page<Product> getFeaturedProduct(Pageable pageable);
+ "AND p.isVisibleIndividually = TRUE "
+ "AND p.isPublished = TRUE "
+ "AND p.id IN (:productIds) "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move p.id IN (:productIds) to the top condition to utilize the index on the id column.
Passing a large list of productIds in the IN clause may result in a query limit error.
Consider applying batching here.


@Query(value = "SELECT p FROM Product p LEFT JOIN p.productCategories pc LEFT JOIN pc.category c "
@Query(value = "SELECT distinct p FROM Product p LEFT JOIN p.productCategories pc LEFT JOIN pc.category c "
+ "WHERE LOWER(p.name) LIKE %:productName% "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the indexed condition id to the top.
Do we have an index on the product name? If so, using LOWER(p.name) may prevent the index use.

List<ProductThumbnailGetVm> productThumbnailVms = new ArrayList<>();
Page<Product> productPage = productRepository.getFeaturedProduct(pageable);
List<Long> productIds = inventoryService.getProductIdsAddedWarehouse();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current approach of fetching all available products in real-time should work. However, I don't like this approach so much as it impacts the responsibility if the number of products or requests is high. Please consider caching or an event-driven approach.

@@ -875,11 +862,14 @@ public ProductsGetVm getProductsByMultiQuery(
Double endPrice
) {
Pageable pageable = PageRequest.of(pageNo, pageSize);
List<Long> productIds = inventoryService.getProductIdsAddedWarehouse();
if (productIds.isEmpty())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the block {} for this if.

@@ -16,4 +16,7 @@ List<Stock> findByWarehouseIdAndProductIdIn(Long warehouseId,
List<Long> productIds);

boolean existsByWarehouseIdAndProductId(Long warehouseId, Long productId);

@Query("SELECT distinct s.productId FROM Stock s")
List<Long> findProductIdsAddedWarehouse();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have cases where quantity = 0? Those records should be excluded, right?
findProductIdsInStock may be a better name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants