Skip to content

Commit

Permalink
Merge pull request #965 from auto-mat/large-desk-performance
Browse files Browse the repository at this point in the history
Fixes: performance and crash
  • Loading branch information
gwasser committed Aug 19, 2021
2 parents 9c6e857 + 63bb949 commit 610460d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
16 changes: 2 additions & 14 deletions helpdesk/query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db.models import Q
from django.core.cache import cache
from django.urls import reverse
from django.utils.html import escape
from django.utils.translation import ugettext as _
Expand Down Expand Up @@ -139,21 +138,10 @@ def __run__(self, queryset):
# https://stackoverflow.com/questions/30487056/django-queryset-contains-duplicate-entries
return queryset.distinct()

def get_cache_key(self):
return str(self.huser.user.pk) + ":" + self.base64

def refresh_query(self):
tickets = self.huser.get_tickets_in_queues().select_related()
ticket_qs = self.__run__(tickets)
cache.set(self.get_cache_key(), ticket_qs, timeout=3600)
return ticket_qs

def get(self):
# Prefilter the allowed tickets
objects = cache.get(self.get_cache_key())
if objects is not None:
return objects
return self.refresh_query()
tickets = self.huser.get_tickets_in_queues().select_related()
return self.__run__(tickets)

def get_datatables_context(self, **kwargs):
"""
Expand Down
7 changes: 4 additions & 3 deletions helpdesk/views/staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ def return_ticketccstring_and_show_subscribe(user, ticket):
# create the ticketcc_string and check whether current user is already
# subscribed
username = user.get_username().upper()
useremail = user.email.upper()
try:
useremail = user.email.upper()
except AttributeError:
useremail = ""
strings_to_check = list()
strings_to_check.append(username)
strings_to_check.append(useremail)
Expand Down Expand Up @@ -1127,8 +1130,6 @@ def ticket_list(request):

urlsafe_query = query_to_base64(query_params)

Query(huser, base64query=urlsafe_query).refresh_query()

user_saved_queries = SavedSearch.objects.filter(Q(user=request.user) | Q(shared__exact=True))

search_message = ''
Expand Down

0 comments on commit 610460d

Please sign in to comment.