Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
Add silky python profiler configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksellen committed Jul 25, 2023
1 parent 12862b2 commit b0b127e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/asgi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup_postgres(connection, **kwargs):


api_app = get_asgi_application()
api_prefixes = ['/api/', '/docs/', '/api-auth/']
api_prefixes = ['/api/', '/docs/', '/api-auth/', '/silk/']

if settings.DEBUG:
api_prefixes.append('/_templates')
Expand Down
4 changes: 4 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@
# for now, log only requests that have recording enabled
SILKY_INTERCEPT_FUNC = lambda request: 'silky_record_requests' in request.COOKIES # noqa: E731

# silk profiling
SILKY_PYTHON_PROFILER = True
SILKY_PYTHON_PROFILER_FUNC = lambda request: 'silky_record_requests' in request.COOKIES # noqa: E731

# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/

Expand Down
27 changes: 17 additions & 10 deletions karrot/applications/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from silk.profiling.profiler import silk_profile

from django.conf import settings
from django.db import models, transaction
Expand Down Expand Up @@ -60,16 +61,22 @@ def accept(self, accepted_by):
self.status = ApplicationStatus.ACCEPTED.value
self.decided_by = accepted_by
self.decided_at = timezone.now()
self.save()
self.group.add_member(
self.user,
added_by=accepted_by,
history_payload={
'accepted_by': accepted_by.id,
'application_date': self.created_at.isoformat(),
}
)
notify_about_accepted_application(self)

with silk_profile('save application'):
self.save()

with silk_profile('add group member'):
self.group.add_member(
self.user,
added_by=accepted_by,
history_payload={
'accepted_by': accepted_by.id,
'application_date': self.created_at.isoformat(),
}
)

with silk_profile('notify accepted application'):
notify_about_accepted_application(self)

@transaction.atomic
def decline(self, declined_by):
Expand Down

0 comments on commit b0b127e

Please sign in to comment.