-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
SQL query formatting improvements #1752
Commits on Mar 27, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 9448bdb - Browse repository at this point
Copy the full SHA 9448bdbView commit details
Commits on Mar 30, 2023
-
Use Python's built-in html.escape()
Because the token values escaped by BoldKeywordFilter are simply intermediate values and are not directly included in HTML templates, use Python's html.escape() instead of django.utils.html.escape() to eliminate the overhead of converting the token values to SafeString. Also pass quote=False when calling escape() since the token values will not be used in quoted attributes.
Configuration menu - View commit details
-
Copy full SHA for ee98c58 - Browse repository at this point
Copy the full SHA ee98c58View commit details -
Replace sqlparse.filters.SerializerUnicode() usage
sqlparse's SerializerUnicode filter does a bunch of fancy whitespace processing which isn't needed because the resulting string will just be inserted into HTML. Replace with a simple EscapedStringSerializer that does nothing but convert the Statement to a properly-escaped string. In the process stop the escaping within BoldKeywordFilter to have a cleaner separation of concerns: BoldKeywordFilter now only handles marking up keywords as bold, while escaping is explicitly handled by the EscapedStringSerializer.
Configuration menu - View commit details
-
Copy full SHA for cd9a189 - Browse repository at this point
Copy the full SHA cd9a189View commit details -
Replace select-list elision implementation
Instead of using a regex to elide the select list in the simplified representation of an SQL query, use an sqlparse filter to elide the select list as a preprocessing step. The result ends up being about 10% faster.
Configuration menu - View commit details
-
Copy full SHA for 496c97d - Browse repository at this point
Copy the full SHA 496c97dView commit details -
Use better heuristic for select list elision
Instead of only eliding select lists longer than 12 characters, now only elide select lists that contain a dot (from a column expression like `table_name`.`column_name`). The motivation for this is that as of Django 1.10, using .count() on a queryset generates SELECT COUNT(*) AS `__count` FROM ... instead of SELECT COUNT(*) FROM ... queries. This change prevents the new form from being elided.
Configuration menu - View commit details
-
Copy full SHA for 3b881fb - Browse repository at this point
Copy the full SHA 3b881fbView commit details
Commits on Apr 2, 2023
-
Only elide top-level select lists
If a query has subselects in its WHERE clause, do not elide the select lists in those subselects.
Configuration menu - View commit details
-
Copy full SHA for ef9cfbb - Browse repository at this point
Copy the full SHA ef9cfbbView commit details -
Apply BoldKeywordFilter after AlignedIndentFilter
The "<strong>" tokens inserted by the BoldKeywordFilter were causing the AlignedIndentFilter to apply excessive indentation to queries which used CASE statements. Fix by rewriting BoldIndentFilter as a statement filter rather than a preprocess filter, and applying after AlignedIndentFilter.
Configuration menu - View commit details
-
Copy full SHA for f45e136 - Browse repository at this point
Copy the full SHA f45e136View commit details -
Only enable SQL grouping for AlignedIndentFilter
When formatting SQL statements using sqparse, grouping only affects the output when AlignedIndentFilter is applied.
Configuration menu - View commit details
-
Copy full SHA for 255efeb - Browse repository at this point
Copy the full SHA 255efebView commit details -
Eliminate intermediate _parse_sql() method
By using a settings_changed signal receiver to clear the query caching, the parse_sql() and _parse_sql() functions can be merged and the check for the "PRETTIFY_SQL" setting can be moved back inside the get_filter_stack() function.
Configuration menu - View commit details
-
Copy full SHA for 3751812 - Browse repository at this point
Copy the full SHA 3751812View commit details -
Configuration menu - View commit details
-
Copy full SHA for e34ec83 - Browse repository at this point
Copy the full SHA e34ec83View commit details