Skip to content

Commit

Permalink
fix: performance
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Oct 12, 2023
1 parent 6a0c4b3 commit 126fcf8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion uniticket/uni_ticket/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def user_is_manager(user, structure):
umos = UserManageOrganizationalStructure
user_structure_manager = umos.objects.filter(
user=user, organizational_structure=structure
).first()
).exists()
if not user_structure_manager:
return False
return user_is_in_default_office(user, structure)
Expand Down
29 changes: 11 additions & 18 deletions uniticket/uni_ticket/views/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,24 @@ def dashboard(request, structure_slug, structure):
office__organizational_structure=structure,
office__is_active=True,
follow=True
).select_related('ticket')
).select_related('ticket').values('ticket')

chiusi = assignments.filter(ticket__is_closed=True).values('ticket__code').annotate(total=Count('ticket__code')).count()
opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False).values('ticket__code').annotate(total=Count('ticket__code')).count()
unassigned = assignments.filter(ticket__assigned_date__isnull=True, ticket__is_closed=False).values('ticket__code').annotate(total=Count('ticket__code')).count()
my_opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False, taken_by=request.user).values('ticket__code').annotate(total=Count('ticket__code')).count()
chiusi = assignments.filter(ticket__is_closed=True).annotate(total=Count('ticket__code')).count()
opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False).annotate(total=Count('ticket__code')).count()
unassigned = assignments.filter(ticket__assigned_date__isnull=True, ticket__is_closed=False).annotate(total=Count('ticket__code')).count()
my_opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False, taken_by=request.user).annotate(total=Count('ticket__code')).count()
om = OrganizationalStructureOffice
offices = om.objects.filter(organizational_structure=structure)\
.prefetch_related('ticketcategory_set')
offices = om.objects.filter(organizational_structure=structure)

cm = TicketCategory
categories = cm.objects.filter(organizational_structure=structure)\
.select_related('organizational_office')\
.prefetch_related('ticketcategorycondition_set')\
.prefetch_related('ticketcategorytask_set')
.select_related('organizational_office')
# disabled_expired_items(categories)

# messages = TicketReply.get_unread_messages_count(tickets=tickets)
ticket_codes = assignments.filter(ticket__is_closed=False).values_list('ticket').distinct()
ticket_codes = assignments.filter(ticket__is_closed=False).distinct()
messages = TicketReply.get_unread_messages_count(tickets=ticket_codes)
# messages = 0
d = {
"categories": categories,
"offices": offices,
Expand Down Expand Up @@ -109,10 +107,7 @@ def offices(request, structure_slug, structure):
title = _("Gestione uffici")
template = "manager/offices.html"
os = OrganizationalStructureOffice
offices = os.objects.filter(organizational_structure=structure)\
.prefetch_related('organizationalstructureofficeemployee_set')\
.prefetch_related('ticketassignment_set')\
.prefetch_related('ticketcategory_set')
offices = os.objects.filter(organizational_structure=structure)

d = {
"offices": offices,
Expand Down Expand Up @@ -2352,9 +2347,7 @@ def categories(request, structure_slug, structure):
# sub_title = _("gestione ufficio livello manager")
categories = TicketCategory.objects\
.filter(organizational_structure=structure)\
.select_related('organizational_office')\
.prefetch_related('ticketcategorycondition_set')\
.prefetch_related('ticketcategorytask_set')
.select_related('organizational_office')
# disabled_expired_items(categories)

d = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ <h5 class="card-title">{{ category.name }}</h5>
{{ category.date_end | default:"-" }}
<br>
<b>{% trans 'Clausole attive' %}:</b>
{{ category.ticketcategorycondition_set.all.count }}
{{ category.ticketcategorycondition_set.count }}
<br>
<b>{% trans 'Attività predefinite attive' %}:</b>
{{ category.ticketcategorytask_set.all.count }}
{{ category.ticketcategorytask_set.count }}
<br>
<b>{% trans 'Notifica email a operatori' %}:</b>
<svg class="icon icon-xs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h5 class="card-title">{{ office.name }}</h5>
<p class="card-text">{{ office.description }}</p>
<p class="card-text">
<b>{% trans 'Operatori' %}:</b>
{{ office.organizationalstructureofficeemployee_set.all.count }}
{{ office.organizationalstructureofficeemployee_set.count }}
<br>
<b>{% trans 'Ad uso interno' %}:</b>
<svg class="icon icon-sm icon-secondary">
Expand All @@ -60,7 +60,7 @@ <h5 class="card-title">{{ office.name }}</h5>
</svg>
<br>
<b>{% trans 'Richieste assegnate' %}:</b>
{{ office.ticketassignment_set.all.count }}
{{ office.ticketassignment_set.count }}
<br>
<b>{% trans 'Categorie di competenza' %}:</b>
{% if office.ticketcategory_set.all %}
Expand Down

0 comments on commit 126fcf8

Please sign in to comment.