laravel-cart-manager icon indicating copy to clipboard operation
laravel-cart-manager copied to clipboard

Performance issue duplicate query when use cart() helper

Open vanthao03596 opened this issue 4 years ago • 1 comments

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:

  1. Clone demo
  2. Install debugbar
  3. We will see duplicate query

Expected behavior No duplicate query during request

Screenshots 1

Additional context Suguest fix: Change bind to singleton in CartManagerServiceProvider

vanthao03596 avatar May 14 '20 02:05 vanthao03596

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.

gauravmak avatar May 16 '20 11:05 gauravmak