Skip to content

Add SQL_TOKEN_GROUPING setting to control token grouping in SQL panel #1404

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Documentation for SQL_TOKEN_GROUPING setting
  • Loading branch information
alkihis committed Nov 20, 2020
commit bd4d1c625e5ee0c0a5cecd0a44689422ed1c59a8
2 changes: 1 addition & 1 deletion debug_toolbar/panels/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def reformat_sql(sql, with_toggle=False):

def parse_sql(sql, aligned_indent=False):
stack = sqlparse.engine.FilterStack()
if dt_settings.get_config()["SQL_STACK_GROUPING"]:
if dt_settings.get_config()["SQL_TOKEN_GROUPING"]:
stack.enable_grouping()
if aligned_indent:
stack.stmtprocess.append(
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"SHOW_TEMPLATE_CONTEXT": True,
"SKIP_TEMPLATE_PREFIXES": ("django/forms/widgets/", "admin/widgets/"),
"SQL_WARNING_THRESHOLD": 500, # milliseconds
"SQL_STACK_GROUPING": True,
"SQL_TOKEN_GROUPING": True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep in line with the rest of the settings, this should likely be either ENABLE_SQL_TOKEN_GROUPING or SQL_ENABLE_TOKEN_GROUPING. @matthiask opinions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request which introduced the code in question was this one: #1116

I don't think anyone understands what "token grouping" should be in this context. Maybe something like PRETTIFY_SQL would describe the intent better and allow us to disable or enable additional prettification features with one setting. The NOUN_VERB format seems to be used with many settings, e.g. "show template context", "enable stacktraces" etc.

}


Expand Down
9 changes: 9 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ Panel options
The SQL panel highlights queries that took more that this amount of time,
in milliseconds, to execute.

* ``SQL_TOKEN_GROUPING``

Default: ``True``

Panel: SQL

Disable SQL token grouping, that might cause render slowdowns,
when a view make long SQL textual queries.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the documentation should briefly explain what grouping of SQL tokens means so that the developer understands what this setting does when it's set to True besides the possible performance impact.


Here's what a slightly customized toolbar configuration might look like::

# This example is unlikely to be appropriate for your project.
Expand Down