-
Notifications
You must be signed in to change notification settings - Fork 158
Optimize OrderedModelBase._wrt_map() - remove unnecessary query #286
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
Merged
shuckc
merged 7 commits into
django-ordered-model:master
from
ibaguio:remove_unecessary_query
Mar 14, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
434153c
fix: utilize order_wrt _id instead of object
ibaguio 3f5aeaf
Add query count tests
ibaguio 46e8bab
run black tests/utils.py
shuckc b416595
add system Check that OrderedQuerySet and OrderedModelManager subclas…
shuckc 6b60ed6
check that order_with_respect_to values are ForeignKey fields
shuckc 048a270
add slowpath for admin that queries FK objects
shuckc 53cd95b
update docs prior to release
shuckc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,41 @@ | ||
# Query count helpers, copied from django source | ||
# Added here for compatibility (django<3.1) | ||
from django.db import DEFAULT_DB_ALIAS, connections | ||
from django.test.utils import CaptureQueriesContext | ||
|
||
|
||
class _AssertNumQueriesContext(CaptureQueriesContext): | ||
def __init__(self, test_case, num, connection): | ||
self.test_case = test_case | ||
self.num = num | ||
super().__init__(connection) | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
super().__exit__(exc_type, exc_value, traceback) | ||
if exc_type is not None: | ||
return | ||
executed = len(self) | ||
self.test_case.assertEqual( | ||
executed, | ||
self.num, | ||
"%d queries executed, %d expected\nCaptured queries were:\n%s" | ||
% ( | ||
executed, | ||
self.num, | ||
"\n".join( | ||
"%d. %s" % (i, query["sql"]) | ||
for i, query in enumerate(self.captured_queries, start=1) | ||
), | ||
), | ||
) | ||
|
||
|
||
def assertNumQueries(self, num, func=None, *args, using=DEFAULT_DB_ALIAS, **kwargs): | ||
conn = connections[using] | ||
|
||
context = _AssertNumQueriesContext(self, num, conn) | ||
if func is None: | ||
return context | ||
|
||
with context: | ||
func(*args, **kwargs) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've added this utils file since this package supports django <3.1, and
assertNumQueries
was only introduced therein