Kaynağa Gözat

Add reverse relations to preselect_related on category view

The availability wrapper needs to look at a product's class, which gives
two extra DB lookups for each product in the list.  This adds 50 DB
queries to the listing view and makes everybody sad.

This fix looks a little ugly but reduces the number of queries to ~25
(with cache enabled).
master
David Winterbottom 13 yıl önce
ebeveyn
işleme
a1a5c05bfa
1 değiştirilmiş dosya ile 6 ekleme ve 0 silme
  1. 6
    0
      oscar/apps/catalogue/views.py

+ 6
- 0
oscar/apps/catalogue/views.py Dosyayı Görüntüle

@@ -98,6 +98,9 @@ def get_product_base_queryset():
98 98
         'product_options',
99 99
         'product_class__options',
100 100
         'stockrecord',
101
+        'stockrecord__product',
102
+        'stockrecord__product__product_class',
103
+        'stockrecord__partner',
101 104
         'images',
102 105
     ).all()
103 106
 
@@ -111,6 +114,9 @@ class ProductCategoryView(ListView):
111 114
     paginate_by = 20
112 115
 
113 116
     def get_categories(self):
117
+        """
118
+        Return a list of the current category and it's ancestors
119
+        """
114 120
         slug = self.kwargs['category_slug']
115 121
         try:
116 122
             category = Category.objects.get(slug=slug)

Loading…
İptal
Kaydet