-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some "db query count" tests, see: #95
- Loading branch information
Showing
3 changed files
with
121 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# coding: utf-8 | ||
|
||
""" | ||
django-reversion-compare unittests | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
:copyleft: 2017 by the django-reversion-compare team, see AUTHORS for more details. | ||
:created: 2017 by Jens Diemer <[email protected]> | ||
:license: GNU GPL v3 or above, see LICENSE for more details. | ||
""" | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
import re | ||
|
||
|
||
def print_db_queries(queries): | ||
queries_data={} | ||
for query in queries: | ||
sql = query["sql"] | ||
queries_data.setdefault(sql, 0) | ||
queries_data[sql] += 1 | ||
duplicates = sum([count - 1 for count in list(queries_data.values())]) | ||
print("-"*79) | ||
print("total queries....: %i" % len(queries)) | ||
print("unique queries...: %i" % len(queries_data)) | ||
print("duplicate queries: %i" % duplicates) | ||
print() | ||
for query, count in sorted(queries_data.items()): | ||
query = re.sub(r'["\'`]', "", query) | ||
print("%s x %s" % (count, query)) | ||
print("-"*79) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters