misc: limit number of SQL queries when computing cell stats (#36842)
This commit is contained in:
parent
fbe8e350c8
commit
94563080dc
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue