Skip to content

Commit 06a6159

Browse files
select_related added to introspect view (#834)
* select_related add to introspect * flake8 fixes * flake8 fix * added author and change log * test for select related * test for select related
1 parent e612c17 commit 06a6159

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Contributors
1010
Abhishek Patel
1111
Alessandro De Angelis
1212
Alan Crosswell
13+
Anvesh Agarwal
1314
Asif Saif Uddin
1415
Ash Christopher
1516
Aristóbulo Meneses

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Security
1515
-->
1616

17+
## [unreleased]
18+
19+
### added
20+
* added `select_related` in intospect view for better query performance
21+
22+
1723
## [1.3.2] 2020-03-24
1824

1925
### Fixed

oauth2_provider/views/introspect.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class IntrospectTokenView(ClientProtectedScopedResourceView):
2424
@staticmethod
2525
def get_token_response(token_value=None):
2626
try:
27-
token = get_access_token_model().objects.get(token=token_value)
27+
token = get_access_token_model().objects.select_related(
28+
"user", "application"
29+
).get(token=token_value)
2830
except ObjectDoesNotExist:
2931
return HttpResponse(
3032
content=json.dumps({"active": False}),

tests/test_introspection_view.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,7 @@ def test_view_post_invalid_client_creds_plaintext(self):
321321
"client_id": self.application.client_id,
322322
"client_secret": self.application.client_secret + "_so_wrong"})
323323
self.assertEqual(response.status_code, 403)
324+
325+
def test_select_related_in_view_for_less_db_queries(self):
326+
with self.assertNumQueries(1):
327+
self.client.post(reverse("oauth2_provider:introspect"))

0 commit comments

Comments
 (0)