From 94563080dc8e536d1ff5ea6e227356fd3c6de8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 15 Oct 2019 18:12:43 +0200 Subject: [PATCH] misc: limit number of SQL queries when computing cell stats (#36842) --- combo_plugin_gnm/views.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/combo_plugin_gnm/views.py b/combo_plugin_gnm/views.py index 5d440dc..35c44cb 100644 --- a/combo_plugin_gnm/views.py +++ b/combo_plugin_gnm/views.py @@ -24,6 +24,7 @@ from django.template import RequestContext from django.template.loader import render_to_string from combo.apps.dashboard.models import Tile +from combo.data.models import ConfigJsonCell from combo.utils import requests, get_templated_url def plusone(request, *args, **kwargs): @@ -76,8 +77,14 @@ def stats(request, *args, **kwargs): data['tiles'] = {} tiles_by_user = {} manual_tiles_by_user = {} - for tile in Tile.objects.all().filter(dashboard__isnull=False).select_related(): - cell = tile.cell + + # preload + cells = {} + for cell in ConfigJsonCell.objects.filter(placeholder__in=['_dashboard', '_suggested_tile']): + cells[cell.id] = cell + + for tile in Tile.objects.filter(dashboard__isnull=False): + cell = cells[tile.cell_pk] # no db access if cell.key not in settings.JSON_CELL_TYPES: continue