-
-
Notifications
You must be signed in to change notification settings - Fork 339
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
Added support of Oracle #619
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Generated by Django 1.9.7 on 2018-01-10 14:14 | ||
|
||
from django.db import migrations, models | ||
from django.db.backends.utils import truncate_name | ||
|
||
import silk.storage | ||
|
||
|
||
def create_autoinc(table_name, column_name): | ||
def autoinc(apps, schema_editor): | ||
autoinc_sql = schema_editor.connection.ops.autoinc_sql(table_name, column_name) | ||
if autoinc_sql: | ||
schema_editor.deferred_sql.extend(autoinc_sql) | ||
|
||
return autoinc | ||
|
||
|
||
def remove_autoinc(table_name, column_name): | ||
def autoinc(apps, schema_editor): | ||
def _get_trigger_name(table): | ||
name_length = schema_editor.connection.ops.max_name_length() - 3 | ||
return schema_editor.connection.ops.quote_name('%s_TR' % truncate_name(table, name_length).upper()) | ||
|
||
seq_sql = schema_editor.connection.ops.drop_sequence_sql(table_name) | ||
if seq_sql: | ||
schema_editor.execute(seq_sql) | ||
schema_editor.execute('DROP TRIGGER %s;' % _get_trigger_name(table_name)) | ||
|
||
return autoinc | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('silk', '0008_sqlquery_analysis'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='response', | ||
name='request' | ||
), | ||
migrations.RemoveField( | ||
model_name='sqlquery', | ||
name='request' | ||
), | ||
migrations.RemoveField( | ||
model_name='profile', | ||
name='request' | ||
), | ||
Comment on lines
+39
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this valid? I don't see this appearing in |
||
|
||
migrations.RemoveField( | ||
model_name='request', | ||
name='id' | ||
), | ||
migrations.RemoveField( | ||
model_name='response', | ||
name='id' | ||
), | ||
|
||
migrations.AddField( | ||
model_name='request', | ||
name='id', | ||
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), | ||
), | ||
migrations.AddField( | ||
model_name='response', | ||
name='id', | ||
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), | ||
), | ||
|
||
migrations.AddField( | ||
model_name='response', | ||
name='request', | ||
field=models.OneToOneField(to='silk.Request', related_name='response', on_delete=models.CASCADE), | ||
), | ||
migrations.AddField( | ||
model_name='sqlquery', | ||
name='request', | ||
field=models.ForeignKey(to='silk.Request', blank=True, null=True, related_name='queries', on_delete=models.CASCADE), | ||
), | ||
migrations.AddField( | ||
model_name='profile', | ||
name='request', | ||
field=models.ForeignKey(to='silk.Request', blank=True, null=True, on_delete=models.CASCADE), | ||
), | ||
|
||
migrations.RunPython(create_autoinc('silk_request', 'id'), remove_autoinc('silk_request', 'id')), | ||
migrations.RunPython(create_autoinc('silk_response', 'id'), remove_autoinc('silk_response', 'id')), | ||
migrations.AlterField( | ||
model_name='request', | ||
name='prof_file', | ||
field=models.FileField( | ||
default='', | ||
max_length=300, | ||
null=True, | ||
blank=True, | ||
storage=silk.storage.ProfilerResultStorage(), | ||
), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
import json | ||
import random | ||
import re | ||
from uuid import uuid4 | ||
|
||
import sqlparse | ||
from django.core.files.storage import get_storage_class | ||
|
@@ -58,7 +57,6 @@ def __init__(self, d): | |
|
||
|
||
class Request(models.Model): | ||
id = CharField(max_length=36, default=uuid4, primary_key=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default id field for a django model is going to be a BigAutoField which is an integer field. Removing this line would change a |
||
path = CharField(max_length=190, db_index=True) | ||
query_params = TextField(blank=True, default='') | ||
raw_body = TextField(blank=True, default='') | ||
|
@@ -76,7 +74,7 @@ class Request(models.Model): | |
meta_num_queries = IntegerField(null=True, blank=True) | ||
meta_time_spent_queries = FloatField(null=True, blank=True) | ||
pyprofile = TextField(blank=True, default='') | ||
prof_file = FileField(max_length=300, blank=True, storage=silk_storage) | ||
prof_file = FileField(max_length=300, default='', null=True, blank=True, storage=silk_storage) | ||
|
||
# Useful method to create shortened copies of strings without losing start and end context | ||
# Used to ensure path and view_name don't exceed 190 characters | ||
|
@@ -192,7 +190,6 @@ def save(self, *args, **kwargs): | |
|
||
|
||
class Response(models.Model): | ||
id = CharField(max_length=36, default=uuid4, primary_key=True) | ||
request = OneToOneField( | ||
Request, related_name='response', db_index=True, | ||
on_delete=models.CASCADE, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,10 @@ | |
import logging | ||
from datetime import datetime, timedelta | ||
|
||
from django.db.models import Count, Q, Sum | ||
from django.db.models import Count, OuterRef, Q, Subquery, Sum | ||
from django.utils import timezone | ||
|
||
from silk.models import SQLQuery | ||
from silk.profiling.dynamic import _get_module | ||
from silk.templatetags.silk_filters import _silk_date_time | ||
|
||
|
@@ -163,7 +164,15 @@ def __str__(self): | |
return '#queries >= %s' % self.value | ||
|
||
def contribute_to_query_set(self, query_set): | ||
return query_set.annotate(num_queries=Count('queries')) | ||
return query_set.annotate( | ||
# This is overly complex due to Oracle not accepting group by on TextField | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
num_queries=Subquery( | ||
SQLQuery.objects.filter(request_id=OuterRef('id')) | ||
.values('request_id') | ||
.annotate(count=Count('id')) | ||
.values('count')[:1] | ||
), | ||
) | ||
|
||
|
||
class TimeSpentOnQueriesFilter(BaseFilter): | ||
|
@@ -178,7 +187,15 @@ def __str__(self): | |
return 'DB Time >= %s' % self.value | ||
|
||
def contribute_to_query_set(self, query_set): | ||
return query_set.annotate(db_time=Sum('queries__time_taken')) | ||
return query_set.annotate( | ||
# This is overly complex due to Oracle not accepting group by on TextField | ||
db_time=Subquery( | ||
SQLQuery.objects.filter(request_id=OuterRef('id')) | ||
.values('request_id') | ||
.annotate(sum_time_taken=Sum('time_taken')) | ||
.values('sum_time_taken')[:1] | ||
), | ||
) | ||
|
||
|
||
class OverallTimeFilter(BaseFilter): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very old version of Django. Should this file be regenerated using a supported version of django?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, a migration here may require the parent django application to run the migration when upgrading/downgrading django-silk which we should avoid, or if we really need to, should be very clearly messaged in the changelog.
As this migration is currently written, I think upgrading django-silk would require wiping the silk database and downgrading django-silk would not be supported (unless several manual steps are taken to reset the django-silk database which would also involve wiping the database). This PR would need be a breaking change requiring a major version bump.