Skip to content

Commit 8cd75b1

Browse files
committed
Merge pull request #62 from mattrobenolt/filtered-queries
Added support to filter queries based on regex patterns
2 parents 5d8abcf + 7ab2d49 commit 8cd75b1

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ Outputs queries as they happen to the terminal, including time taken.
117117
Disable SQL query truncation (used in SQLRealTimeModule) with the ``DEVSERVER_TRUNCATE_SQL`` setting::
118118
119119
DEVSERVER_TRUNCATE_SQL = False
120+
Filter SQL queries with the ``DEVSERVER_FILTER_SQL`` setting::
121+
122+
DEVSERVER_FILTER_SQL = (
123+
re.compile('djkombu_\w+'), # Filter all queries related to Celery
124+
)
120125

121126
devserver.modules.sql.SQLSummaryModule
122127
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

devserver/modules/sql.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ def execute(self, sql, params=()):
6161
formatted_sql = sql % (params if isinstance(params, dict) else tuple(params))
6262
if self.logger:
6363
message = formatted_sql
64-
if settings.DEVSERVER_TRUNCATE_SQL:
65-
message = truncate_sql(message, aggregates=settings.DEVSERVER_TRUNCATE_AGGREGATES)
66-
message = sqlparse.format(message, reindent=True, keyword_case='upper')
67-
self.logger.debug(message)
64+
if settings.DEVSERVER_FILTER_SQL:
65+
if any(filter_.search(message) for filter_ in settings.DEVSERVER_FILTER_SQL):
66+
message = None
67+
if message is not None:
68+
if settings.DEVSERVER_TRUNCATE_SQL:
69+
message = truncate_sql(message, aggregates=settings.DEVSERVER_TRUNCATE_AGGREGATES)
70+
message = sqlparse.format(message, reindent=True, keyword_case='upper')
71+
self.logger.debug(message)
6872

6973
start = datetime.now()
7074

devserver/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# 'devserver.modules.cache.CacheSummaryModule',
1111
))
1212

13+
DEVSERVER_FILTER_SQL = getattr(settings, 'DEVSERVER_FILTER_SQL', False)
1314
DEVSERVER_TRUNCATE_SQL = getattr(settings, 'DEVSERVER_TRUNCATE_SQL', True)
1415

1516
DEVSERVER_TRUNCATE_AGGREGATES = getattr(settings, 'DEVSERVER_TRUNCATE_AGGREGATES', getattr(settings, 'DEVSERVER_TRUNCATE_AGGREGATES', False))

0 commit comments

Comments
 (0)