Avoid unneccesary logs in some highly-used API endpoints

This commit is contained in:
Raphael Michel
2019-06-09 23:54:48 +02:00
parent b2274039b3
commit 61e111742d
3 changed files with 30 additions and 0 deletions
+5
View File
@@ -244,6 +244,11 @@ class SubEventViewSet(ConditionalListView, viewsets.ModelViewSet):
)
def perform_update(self, serializer):
if serializer.data == self.get_serializer(instance=serializer.instance).data:
# Performance optimization: If nothing was changed, we do not need to save or log anything.
# This costs us a few cycles on save, but avoids thousands of lines in our log.
return
super().perform_update(serializer)
serializer.instance.log_action(
+9
View File
@@ -65,6 +65,10 @@ class ItemViewSet(ConditionalListView, viewsets.ModelViewSet):
return ctx
def perform_update(self, serializer):
if serializer.data == self.get_serializer(instance=serializer.instance).data:
# Performance optimization: If nothing was changed, we do not need to save or log anything.
# This costs us a few cycles on save, but avoids thousands of lines in our log.
return
serializer.save(event=self.request.event)
serializer.instance.log_action(
'pretix.event.item.changed',
@@ -452,6 +456,11 @@ class QuotaViewSet(ConditionalListView, viewsets.ModelViewSet):
return ctx
def perform_update(self, serializer):
if serializer.data == self.get_serializer(instance=serializer.instance).data:
# Performance optimization: If nothing was changed, we do not need to save or log anything.
# This costs us a few cycles on save, but avoids thousands of lines in our log.
return
current_subevent = serializer.instance.subevent
serializer.save(event=self.request.event)
request_subevent = serializer.instance.subevent
+16
View File
@@ -1553,6 +1553,22 @@ def test_quota_update(token_client, organizer, event, quota, item):
quota = Quota.objects.get(pk=resp.data['id'])
assert quota.name == "Ticket Quota Update"
assert quota.size == 111
assert quota.all_logentries().count() == 1
@pytest.mark.django_db
def test_quota_update_unchanged(token_client, organizer, event, quota, item):
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/quotas/{}/'.format(organizer.slug, event.slug, quota.pk),
{
"size": 200,
},
format='json'
)
assert resp.status_code == 200
quota = Quota.objects.get(pk=resp.data['id'])
assert quota.size == 200
assert quota.all_logentries().count() == 0
@pytest.mark.django_db