From 9d97d1c5107c632051396d9daff680ab330fc783 Mon Sep 17 00:00:00 2001 From: Owocki Date: Fri, 31 May 2019 10:23:57 -0600 Subject: [PATCH 1/2] api results speed --- app/assets/v2/js/pages/dashboard.js | 2 +- app/assets/v2/js/shared.js | 2 +- app/dashboard/router.py | 19 +++++++++++++++++++ .../templates/shared/bounty-popover.html | 11 ----------- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/assets/v2/js/pages/dashboard.js b/app/assets/v2/js/pages/dashboard.js index 86fc0f053aa..2780341100f 100644 --- a/app/assets/v2/js/pages/dashboard.js +++ b/app/assets/v2/js/pages/dashboard.js @@ -291,7 +291,7 @@ var removeFilter = function(key, value) { }; var get_search_URI = function(offset, order) { - var uri = '/api/v0.1/bounties/?'; + var uri = '/api/v0.1/bounties/slim/?'; var keywords = ''; var org = ''; diff --git a/app/assets/v2/js/shared.js b/app/assets/v2/js/shared.js index 9a933a9dffe..6d106caa0c8 100644 --- a/app/assets/v2/js/shared.js +++ b/app/assets/v2/js/shared.js @@ -1229,7 +1229,7 @@ function renderBountyRowsFromResults(results, renderForExplorer) { } else { result['hidden'] = (i > 4); } - + html += tmpl.render(result); } return html; diff --git a/app/dashboard/router.py b/app/dashboard/router.py index c1859fe161d..48728d660ba 100644 --- a/app/dashboard/router.py +++ b/app/dashboard/router.py @@ -176,6 +176,19 @@ def update(self, validated_data): return bounty +class BountySerializerSlim(BountySerializer): + + + class Meta: + """Define the bounty serializer metadata.""" + model = Bounty + fields = ( + 'url', 'title', 'experience_level', 'status', 'fulfillment_accepted_on', + 'fulfillment_started_on', 'fulfillment_submitted_on', 'canceled_on', 'web3_created', 'bounty_owner_address', + 'avatar_url', 'network', 'standard_bounties_id', 'github_org_name', 'interested', 'token_name', 'value_in_usdt', + 'keywords', 'value_in_token', 'project_type', 'is_open', 'expires_date' + ) + class BountyViewSet(viewsets.ModelViewSet): """Handle the Bounty view behavior.""" queryset = Bounty.objects.prefetch_related('fulfillments', 'interested', 'interested__profile', 'activities', 'unsigned_nda') \ @@ -379,6 +392,12 @@ def get_queryset(self): return queryset +class BountyViewSetSlim(BountyViewSet): + queryset = Bounty.objects.all().order_by('-web3_created') + serializer_class = BountySerializerSlim + + # Routers provide an easy way of automatically determining the URL conf. router = routers.DefaultRouter() +router.register(r'bounties/slim', BountyViewSetSlim) router.register(r'bounties', BountyViewSet) diff --git a/app/dashboard/templates/shared/bounty-popover.html b/app/dashboard/templates/shared/bounty-popover.html index b67592a5914..3f857b1ea39 100644 --- a/app/dashboard/templates/shared/bounty-popover.html +++ b/app/dashboard/templates/shared/bounty-popover.html @@ -48,15 +48,4 @@ [[if expired !== ""]][[/if]][[:expired]] - [[if activities.length]] - - [[/if]] From 2e71b7f8a805f92cab813954c7f4f8c0bbfe3559 Mon Sep 17 00:00:00 2001 From: Owocki Date: Fri, 31 May 2019 13:41:52 -0600 Subject: [PATCH 2/2] adds in latest activity again --- app/dashboard/models.py | 8 ++++++++ app/dashboard/router.py | 2 +- app/dashboard/templates/shared/bounty-popover.html | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/dashboard/models.py b/app/dashboard/models.py index c1466e9927e..f83465d9eb3 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -328,6 +328,14 @@ def save(self, *args, **kwargs): self.github_url = clean_bounty_url(self.github_url) super().save(*args, **kwargs) + @property + def latest_activity(self): + activity = Activity.objects.filter(bounty=self.pk).order_by('-pk') + if activity.exists(): + from dashboard.router import ActivitySerializer + return ActivitySerializer(activity.first()).data + return None + @property def profile_pairs(self): profile_handles = [] diff --git a/app/dashboard/router.py b/app/dashboard/router.py index 48728d660ba..0fb78603a5c 100644 --- a/app/dashboard/router.py +++ b/app/dashboard/router.py @@ -186,7 +186,7 @@ class Meta: 'url', 'title', 'experience_level', 'status', 'fulfillment_accepted_on', 'fulfillment_started_on', 'fulfillment_submitted_on', 'canceled_on', 'web3_created', 'bounty_owner_address', 'avatar_url', 'network', 'standard_bounties_id', 'github_org_name', 'interested', 'token_name', 'value_in_usdt', - 'keywords', 'value_in_token', 'project_type', 'is_open', 'expires_date' + 'keywords', 'value_in_token', 'project_type', 'is_open', 'expires_date', 'latest_activity' ) class BountyViewSet(viewsets.ModelViewSet): diff --git a/app/dashboard/templates/shared/bounty-popover.html b/app/dashboard/templates/shared/bounty-popover.html index 3f857b1ea39..7ea1365f5b2 100644 --- a/app/dashboard/templates/shared/bounty-popover.html +++ b/app/dashboard/templates/shared/bounty-popover.html @@ -48,4 +48,13 @@ [[if expired !== ""]][[/if]][[:expired]] + [[if latest_activity]] + + [[/if]]