Skip to content

Commit

Permalink
3N + 1 query optimization | 3N - viewers, commenters, owner | after s…
Browse files Browse the repository at this point in the history
…ubmitting the task
  • Loading branch information
Kenan7 committed Feb 16, 2021
1 parent 9817108 commit ffc3f15
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DEBUG=1
CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/0
DATABASE_URL=postgres://kenan:kkk@localhost:5433/fileshare
REDIS_CHANNEL_HOST=localhost
REDIS_CHANNEL_PORT=6379
15 changes: 13 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Python: Django",
"name": "Local - Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver"
],
"django": true,
"envFile": "${workspaceFolder}/.env.local",
"justMyCode": false
},
{
"name": "Staging - Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
Expand Down
6 changes: 5 additions & 1 deletion labrin_task/fileapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ class FileListView(LoginRequiredMixin, ListView):

def get_queryset(self):
current_user = User.objects.get(id=self.request.user.id)
return FileModel.objects.filter(owner=current_user)
return (
FileModel.objects.filter(owner=current_user)
.select_related("owner")
.prefetch_related("viewers", "commenters")
)


file_list_view = FileListView.as_view()
Expand Down

0 comments on commit ffc3f15

Please sign in to comment.