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

Fixing Depreciation, Saving and Performance Tweaks #104

Merged
merged 5 commits into from
Mar 13, 2016
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 project/tests/test_config_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _execute_request(self):
delete_all_models(Request)
DataCollector().configure(Request.objects.create())
response = self._mock_response()
SilkyMiddleware()._process_response(response)
SilkyMiddleware()._process_response('', response)
self.assertTrue(response.status_code == 200)
objs = Request.objects.all()
self.assertEqual(objs.count(), 1)
Expand Down
17 changes: 11 additions & 6 deletions silk/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def silky_reverse(name, *args, **kwargs):
r = reverse(name, *args, **kwargs)
return r


fpath = silky_reverse('summary')
config = SilkyConfig()

Expand All @@ -49,7 +50,6 @@ def _should_intercept(request):


class TestMiddleware(object):

def process_response(self, request, response):
return response

Expand Down Expand Up @@ -94,10 +94,12 @@ def process_request(self, request):
SQLCompiler._execute_sql = SQLCompiler.execute_sql
SQLCompiler.execute_sql = execute_sql
request_model = RequestModelFactory(request).construct_request_model()
DataCollector().configure(request_model)
DataCollector().configure(request_model)
else:
DataCollector().clear()

@transaction.atomic()
def _process_response(self, response):
def _process_response(self, request, response):
Logger.debug('Process response')
with silk_meta_profiler():
collector = DataCollector()
Expand All @@ -106,9 +108,12 @@ def _process_response(self, response):
if silk_request:
silk_response = ResponseModelFactory(response).construct_response_model()
silk_response.save()
silk_request.end_time = timezone.now()
collector.finalise()
else:
Logger.error(
'No request model was available when processing response. Did something go wrong in process_request/process_view?')
Logger.error('No request model was available when processing response. '
'Did something go wrong in process_request/process_view?'
'\n' + str(request) + '\n\n' + str(response))
# Need to save the data outside the silk_meta_profiler
# Otherwise the meta time collected in the context manager
# is not taken in account
Expand All @@ -118,5 +123,5 @@ def _process_response(self, response):

def process_response(self, request, response):
if getattr(request, 'silk_is_intercepted', False):
self._process_response(response)
self._process_response(request, response)
return response
2 changes: 1 addition & 1 deletion silk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def save(self, *args, **kwargs):
if not self.pk:
if self.request:
self.request.num_sql_queries += 1
self.request.save()
self.request.save(update_fields=['num_sql_queries'])

super(SQLQuery, self).save(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion silk/views/requests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core.context_processors import csrf
from django.template.context_processors import csrf

from django.db.models import Sum
from django.shortcuts import render_to_response
Expand Down
2 changes: 1 addition & 1 deletion silk/views/summary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core.context_processors import csrf
from django.template.context_processors import csrf
from django.db.models import Avg, Count, Sum, Max
from django.shortcuts import render_to_response
from django.utils.decorators import method_decorator
Expand Down