Investigating Slow Performance in Adding Products to Django Oscar Basket via REST API

61 Views Asked by At

I'm currently facing performance issues when adding products to the shopping cart in a Django Oscar-based e-commerce application. The problem becomes particularly noticeable when the basket contains around 50 items. I'm using Django Oscar's REST API for adding products to the basket, which is called by JavaScript. The challenge is to identify the root cause of the slowdown and explore possible solutions.

Observations:

  1. Adding products through product list views is slow.
  2. Adding products through the product detail page remains fast even with a considerable number of products in the cart.

Details:

Investigation So Far:

  • Middleware Approach: For direct adding via the detail page, offer calculations are handled in Django Oscar's BasketMiddleware during the redirect page load. This code might be better optimized compared to the custom code in the API.

  • Offer Calculation in API: The problem intensifies when the basket consists of 30+ basket lines with different products. The query count increases linearly with the basket line count during API calls.

Request for Help:

I'm seeking advice/practical examples of approach on optimizing the API calls to use a similar number of queries as the direct adding via the detail page. While getting more queries is expected and unavoidable, if there are ways to align the API's query count with the more optimized detail page approach, it would significantly improve performance.

Django-silk Report:

List-view-product-adding-22-different-products: List-view-product-adding-22-different-products:

12 basket lines that were added from list view: after that i added 3 more different product from detail view: enter image description here

Thank you for your insights and suggestions.

0

There are 0 best solutions below