-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add middleware and installation instructions
- Loading branch information
Showing
12 changed files
with
179 additions
and
19 deletions.
There are no files selected for viewing
Empty file.
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/sh | ||
|
||
make format | ||
make format-check | ||
make typecheck | ||
|
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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
from .errors import NPlusOneError, QuerySpyError | ||
from .listeners import reset | ||
from .listeners import queryspy_context, setup, teardown | ||
|
||
__all__ = ["QuerySpyError", "NPlusOneError", "reset"] | ||
__all__ = [ | ||
"QuerySpyError", | ||
"NPlusOneError", | ||
"setup", | ||
"teardown", | ||
"queryspy_context", | ||
] |
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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
from django.apps import AppConfig | ||
|
||
from .listeners import reset as setup_listeners | ||
from .patch import patch | ||
|
||
|
||
class QuerySpyConfig(AppConfig): | ||
name = "queryspy" | ||
|
||
def ready(self): | ||
setup_listeners() | ||
patch() | ||
pass |
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,10 @@ | ||
from .listeners import queryspy_context | ||
|
||
|
||
def queryspy_middleware(get_response): | ||
def middleware(request): | ||
with queryspy_context(): | ||
response = get_response(request) | ||
return response | ||
|
||
return middleware |
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,30 @@ | ||
from django.http import HttpRequest, JsonResponse | ||
|
||
from .models import User | ||
|
||
|
||
def single_user_and_profile(request: HttpRequest, id: int): | ||
user = User.objects.get(id=id) | ||
return JsonResponse( | ||
data={ | ||
"username": user.username, | ||
"display_name": user.profile.display_name, | ||
} | ||
) | ||
|
||
|
||
def all_users_and_profiles(request: HttpRequest): | ||
""" | ||
This view has an N+1. | ||
""" | ||
return JsonResponse( | ||
data={ | ||
"users": [ | ||
{ | ||
"username": user.username, | ||
"display_name": user.profile.display_name, | ||
} | ||
for user in User.objects.all() | ||
] | ||
} | ||
) |
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,8 @@ | ||
from django.urls import path | ||
|
||
from .social.views import all_users_and_profiles, single_user_and_profile | ||
|
||
urlpatterns = [ | ||
path("users/", all_users_and_profiles), | ||
path("user/<int:id>/", single_user_and_profile), | ||
] |
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