Skip to content

Commit

Permalink
[chores] Optimized controller add_tagged_templates method
Browse files Browse the repository at this point in the history
Add all templates in one query instead of multiple queries.
  • Loading branch information
nemesifier committed Mar 11, 2021
1 parent 6137b77 commit d236b34
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions openwisp_controller/config/controller/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ def add_tagged_templates(self, config, request):
# retrieve tags and add them to current config
tags = tags.split()
queryset = self.get_template_queryset(config)
templates = queryset.filter(tags__name__in=tags).only('id').distinct()
for template in templates:
config.templates.add(template)
tagged_templates = queryset.filter(tags__name__in=tags).only('id').distinct()
if tagged_templates:
config.templates.add(*tagged_templates)

def invalid(self, request):
"""
Expand Down

0 comments on commit d236b34

Please sign in to comment.