From 223c89cd5eebfa0328597d23165fbff03bed4978 Mon Sep 17 00:00:00 2001 From: Owocki Date: Tue, 9 Jul 2019 14:36:40 -0600 Subject: [PATCH 1/2] profile perofrmance --- app/dashboard/views.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 9f53d4ca923..d133a86f85e 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -1983,18 +1983,29 @@ def profile(request, handle): context['ratings'] = range(0,5) tabs = [] + counts = all_activities.values('activity_type').order_by('activity_type').annotate(the_count=Count('activity_type')) + counts = {ele['activity_type']: ele['the_count'] for ele in counts} for tab, name in activity_tabs: - activities = profile_filter_activities(all_activities, tab) - activities_count = activities.count() + # this functions as profile_filter_activities does + # except w. aggregate counts + + if tab == 'all': + activities_count = sum([val for key, val in counts.items()]) + else: + activities_count = counts.get(tab, 0) + if tab == 'start_work': + activities_count += counts['worker_approved'] + + + # dont draw a tab where the activities count is 0 if activities_count == 0: continue - paginator = Paginator(activities, 10) - + # buidl dict obj = {'id': tab, 'name': name, - 'objects': paginator.get_page(1), + 'objects': [], 'count': activities_count, 'type': 'activity' } From bc0bce63b0de6ee2f5ff5c20af893d60c96acf25 Mon Sep 17 00:00:00 2001 From: Kevin Owocki Date: Tue, 9 Jul 2019 15:03:23 -0600 Subject: [PATCH 2/2] .get --- app/dashboard/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dashboard/views.py b/app/dashboard/views.py index d133a86f85e..b05e1dc4ee8 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -1995,7 +1995,7 @@ def profile(request, handle): else: activities_count = counts.get(tab, 0) if tab == 'start_work': - activities_count += counts['worker_approved'] + activities_count += counts.get("worker_approved", 0) # dont draw a tab where the activities count is 0