Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api results speed down from 1.5s to 0.4s #4550

Merged
merged 2 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';

Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ function renderBountyRowsFromResults(results, renderForExplorer) {
} else {
result['hidden'] = (i > 4);
}

html += tmpl.render(result);
}
return html;
Expand Down
8 changes: 8 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
19 changes: 19 additions & 0 deletions app/dashboard/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', 'latest_activity'
)

class BountyViewSet(viewsets.ModelViewSet):
"""Handle the Bounty view behavior."""
queryset = Bounty.objects.prefetch_related('fulfillments', 'interested', 'interested__profile', 'activities', 'unsigned_nda') \
Expand Down Expand Up @@ -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)
8 changes: 3 additions & 5 deletions app/dashboard/templates/shared/bounty-popover.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@
[[if expired !== ""]]<i class="far fa-clock expired-icon"></i>[[/if]][[:expired]]
</div>
</div>
[[if activities.length]]
[[if latest_activity]]
<div class="popover-bounty__footer">
<span class="title">{% trans "Latest Activity" %}</span>
[[for activities.slice(-1) ]]
<div class="d-flex justify-content-between">
<span>[[activitytext:activity_type]] {% trans "by" %} <b>[[:profile.handle]]</b></span>
<span>[[timedifference:created]]</span>
<span>[[activitytext:latest_activity.activity_type]] {% trans "by" %} <b>[[:latest_activity.profile.handle]]</b></span>
<span>[[timedifference:latest_activity.created]]</span>
</div>
[[/for]]
</div>
[[/if]]
</div>