perfs: limit cells considered for cell.modify_global_context (#21052)
This commit is contained in:
parent
a049d749e6
commit
85b3ddc697
|
@ -356,6 +356,10 @@ class CellBase(models.Model):
|
|||
# get_badge(self, context); set to None so cell types can be skipped easily
|
||||
get_badge = None
|
||||
|
||||
# modify_global_context(self, context, request=None)
|
||||
# Apply changes to the template context that must visible to all cells in the page
|
||||
modify_global_context = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
@ -526,10 +530,6 @@ class CellBase(models.Model):
|
|||
tmpl = template.loader.select_template(template_names)
|
||||
return tmpl.render(context, context.get('request'))
|
||||
|
||||
def modify_global_context(self, context, request=None):
|
||||
'''Apply changes to the template context that must visible to all cells in the page'''
|
||||
return context
|
||||
|
||||
def render_for_search(self):
|
||||
if not self.is_enabled():
|
||||
return ''
|
||||
|
|
|
@ -112,12 +112,15 @@ def render_cell(request, cell):
|
|||
}
|
||||
|
||||
if cell.page_id:
|
||||
other_cells = CellBase.get_cells(page_id=cell.page_id)
|
||||
other_cells = []
|
||||
for klass in CellBase.get_cell_classes(lambda x: bool(x.modify_global_context)):
|
||||
other_cells.extend(klass.objects.filter(page_id=cell.page_id))
|
||||
other_cells = [x for x in other_cells if x.is_visible(user=request.user)]
|
||||
other_cells.sort(key=lambda x: x.order)
|
||||
for other_cell in other_cells:
|
||||
if other_cell.get_reference() != cell.get_reference():
|
||||
other_cell.modify_global_context(context, request)
|
||||
else:
|
||||
elif cell.modify_global_context:
|
||||
# Cell can pass data through its own __dict__
|
||||
cell.modify_global_context(context, request)
|
||||
|
||||
|
@ -370,7 +373,8 @@ def publish_page(request, page, status=200, template_name=None):
|
|||
}
|
||||
|
||||
for cell in cells:
|
||||
cell.modify_global_context(ctx, request)
|
||||
if cell.modify_global_context:
|
||||
cell.modify_global_context(ctx, request)
|
||||
|
||||
if not template_name:
|
||||
combo_template = settings.COMBO_PUBLIC_TEMPLATES[page.template_name]
|
||||
|
|
Loading…
Reference in New Issue