mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
Return HttpResponse instead of redirects for AJAX follows
This is more efficient, and most follow activities are ajax
This commit is contained in:
parent
923495e454
commit
a7553c0b8c
2 changed files with 10 additions and 3 deletions
|
@ -42,11 +42,11 @@ def get_relationship(context, user_object):
|
|||
"""caches the relationship between the logged in user and another user"""
|
||||
user = context["request"].user
|
||||
return get_or_set(
|
||||
f"cached-relationship-{user.id}-{user_object.id}",
|
||||
f"relationship-{user.id}-{user_object.id}",
|
||||
get_relationship_name,
|
||||
user,
|
||||
user_object,
|
||||
timeout=259200,
|
||||
timeout=60 * 60,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
""" views for actions you can take in the application """
|
||||
import urllib.parse
|
||||
import re
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.views.decorators.http import require_POST
|
||||
|
@ -13,6 +15,7 @@ from .helpers import (
|
|||
handle_remote_webfinger,
|
||||
subscribe_remote_webfinger,
|
||||
WebFingerError,
|
||||
is_api_request
|
||||
)
|
||||
|
||||
|
||||
|
@ -34,6 +37,8 @@ def follow(request):
|
|||
# that means we should save to trigger a re-broadcast
|
||||
follow_request.save()
|
||||
|
||||
if is_api_request(request):
|
||||
return HttpResponse()
|
||||
return redirect(to_follow.local_path)
|
||||
|
||||
|
||||
|
@ -58,8 +63,10 @@ def unfollow(request):
|
|||
except models.UserFollowRequest.DoesNotExist:
|
||||
clear_cache(request.user, to_unfollow)
|
||||
|
||||
if is_api_request(request):
|
||||
return HttpResponse()
|
||||
# this is handled with ajax so it shouldn't really matter
|
||||
return redirect(request.headers.get("Referer", "/"))
|
||||
return redirect("/")
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in a new issue