EC-CUBE / EC-CUBE/ec-cube

ProductClass.stockの意味が無くなっている

Open
#5,089 1 comment 2 reactions 0 assignees View on GitHub
improvement
Dominant language
PHP
Stars
788
Forks
719
Avg merge
3d 20h
Merged PRs (30d)
45

Description

## 概要(Overview)
在庫情報は、ProductStock.stockとProductClass.stockにあり、商品一覧などではProductClass.stockを見て、在庫増減のトランザクションが走る場面ではProductStockを使う様にして、ロック待ちを回避するという目的でこの二つがあったが、現状、フロント画面でもProductStockを取得しているので、意味が無くなっている。

dtb_product_classとdtb_prodcut_stockを結合しない様にすると、商品一覧画面で大量に`SELECT * FROM dtb_product_stock...`の様なクエリが発生してしまい、かなり重くなる。

## 期待する内容(Expect) or 要望 (Requirement)
商品一覧画面などでは、ProdcutClass.ProductStockをDBから取得せずに、ProdcutClass.stockを利用する様にしたい。

### 環境 (environment)
+ EC-CUBE: 4.0.x
+ PHP: 7.x.x
+ DB:
- PostgreSQL x.x.x
- MySQL x.x.x

## 関連情報 (Ref)
#3862

fetch modeでどうにかできないかと試してみたが、うまくいかない。
現状のコードでは、`ProdcutRepository::getQueryBuilderBySearchData()`でまず検索して、そこからProduct::idの配列をforeachで取ってきて、それを検索条件に`ProductRepository::findWithSortedClassCategories()`でテーブルを結合していっきにデータを取得している。この`ProductRepository::findWithSortedClassCategories()`が吐くクエリが規格や規格分類が増えると重い。
`ProductRepository::findWithSortedClassCategories()`で結合しているテーブルを一部`ProdcutRepository::getQueryBuilderBySearchData()`に持ってくると、トータルで少し速くなる。

Contributor guide

Open the contributing guide

Research direction

Start by reading ProductRepository::findWithSortedClassCategories() and ProdcutRepository::getQueryBuilderBySearchData(), then reproduce the product-list queries described in the issue. Trace where ProductClass.ProductStock is loaded and verify that the product list uses ProductClass.stock without unnecessary ProductStock retrieval, while preserving inventory transaction behavior and improving query cost.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php, postgresql
Domain
backend, database, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.