old_contents: import logging
  
  from django.utils.translation import get_language
  
  from . import analytics
  from ..product.models import Discount
  
  logger = logging.getLogger(__name__)
  
  
  class GoogleAnalytics(object):
      def process_request(self, request):
          client_id = analytics.get_client_id(request)
          path = request.path
          language = get_language()
          headers = request.META
          # FIXME: on production you might want to run this in background
          try:
              analytics.report_view(client_id, path=path, language=language,
                                    headers=headers)
          except Exception:
              logger.exception('Unable to update analytics')
  
  
  class DiscountMiddleware(object):
      def process_request(self, request):
          discounts = Discount.objects.all()
          discounts = discounts.prefetch_related('products', 'categories')
          request.discounts = discounts
  
new_contents: import logging
  
  from django.utils.translation import get_language
  
  from . import analytics
  from ..product.models import Discount
  
  logger = logging.getLogger(__name__)
  
  
  class GoogleAnalytics(object):
      def process_request(self, request):
          client_id = analytics.get_client_id(request)
          path = request.path
          language = get_language()
          headers = request.META
          # FIXME: on production you might want to run this in background
          try:
              analytics.report_view(client_id, path=path, language=language,
                                    headers=headers)
          except Exception:
              logger.exception('Unable to update analytics')
  
  
  class DiscountMiddleware(object):
      def process_request(self, request):
          discounts = Discount.objects.all()
          discounts = discounts.prefetch_related('products')
          request.discounts = discounts
  
subject: Drop unused prefetch_related