Skip to content

Commit

Permalink
#132 Add action on sql query list
Browse files Browse the repository at this point in the history
  • Loading branch information
SebCorbin committed Oct 27, 2022
1 parent 4934ffe commit 7a9935d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions silk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ def num_joins(self):
count += sum(map(lambda t: t.match(sqlparse.tokens.Keyword, r'\.*join\.*', regex=True), statement.flatten()))
return count

@property
def first_keywords(self):
parsed_query = sqlparse.parse(self.query)
keywords = []
for statement in parsed_query[0].tokens:
if not statement.is_keyword:
break
keywords.append(statement.value)
return ' '.join(keywords)

@property
def tables_involved(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions silk/templates/silk/sql.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<table class="sortable">
<tr>
<th class="left-aligned">At</th>
<th class="left-aligned">Action</th>
<th class="left-aligned">Tables</th>
<th class="right-aligned">Num. Joins</th>
<th class="right-aligned">Execution Time (ms)</th>
Expand All @@ -121,6 +122,7 @@
{% endif %}\
';">
<td class="left-aligned">+{{ sql_query.start_time_relative }}</td>
<td class="left-aligned">{{ sql_query.first_keywords }}</td>
<td class="left-aligned">{{ sql_query.tables_involved|join:", " }}</td>
<td class="right-aligned">{{ sql_query.num_joins }}</td>
<td class="right-aligned">{{ sql_query.time_taken | floatformat:6 }}</td>
Expand Down

0 comments on commit 7a9935d

Please sign in to comment.