Browse Source

API, optimization: avoid retrieving project twice from the database

pull/379/head
Pēteris Caune 4 years ago
parent
commit
fd4d59c4e1
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
1 changed files with 4 additions and 4 deletions
  1. +4
    -4
      hc/api/views.py

+ 4
- 4
hc/api/views.py View File

@ -186,7 +186,7 @@ def channels(request):
@authorize_read @authorize_read
def get_check(request, code): def get_check(request, code):
check = get_object_or_404(Check, code=code) check = get_object_or_404(Check, code=code)
if check.project != request.project:
if check.project_id != request.project.id:
return HttpResponseForbidden() return HttpResponseForbidden()
return JsonResponse(check.to_dict(readonly=request.readonly)) return JsonResponse(check.to_dict(readonly=request.readonly))
@ -196,7 +196,7 @@ def get_check(request, code):
@authorize @authorize
def update_check(request, code): def update_check(request, code):
check = get_object_or_404(Check, code=code) check = get_object_or_404(Check, code=code)
if check.project != request.project:
if check.project_id != request.project.id:
return HttpResponseForbidden() return HttpResponseForbidden()
try: try:
@ -211,7 +211,7 @@ def update_check(request, code):
@authorize @authorize
def delete_check(request, code): def delete_check(request, code):
check = get_object_or_404(Check, code=code) check = get_object_or_404(Check, code=code)
if check.project != request.project:
if check.project_id != request.project.id:
return HttpResponseForbidden() return HttpResponseForbidden()
response = check.to_dict() response = check.to_dict()
@ -237,7 +237,7 @@ def single(request, code):
@authorize @authorize
def pause(request, code): def pause(request, code):
check = get_object_or_404(Check, code=code) check = get_object_or_404(Check, code=code)
if check.project != request.project:
if check.project_id != request.project.id:
return HttpResponseForbidden() return HttpResponseForbidden()
check.status = "paused" check.status = "paused"


Loading…
Cancel
Save