laravel-cart-manager
laravel-cart-manager copied to clipboard
Performance issue duplicate query when use cart() helper
Describe the bug
cart() helper hit database query every time.
example:
protected function getCartDetails() { return [ 'items' => cart()->items($displayCurrency = true), 'totals' => cart()->totals(), ]; }
This function will hit database multiple times.
To Reproduce
Steps to reproduce the behavior:
- Clone demo
- Install debugbar
- We will see duplicate query
Expected behavior No duplicate query during request
Screenshots
Additional context Suguest fix: Change bind to singleton in CartManagerServiceProvider
Thanks for reporting.
As per the current code status, the downside is that the items are not updated in the Cart object array resulting in data inconsistencies. To solve the DB queries issue, we will need to update some parts of the code.