diff --git a/.env.example b/.env.example
index dd7bec4f2..4c1c2eefe 100644
--- a/.env.example
+++ b/.env.example
@@ -32,6 +32,8 @@ REDIS_ACTIVITY_PORT=6379
REDIS_ACTIVITY_PASSWORD=redispassword345
# Optional, use a different redis database (defaults to 0)
# REDIS_ACTIVITY_DB_INDEX=0
+# Alternatively specify the full redis url, i.e. if you need to use a unix:// socket
+# REDIS_ACTIVITY_URL=
# Redis as celery broker
REDIS_BROKER_HOST=redis_broker
@@ -39,6 +41,8 @@ REDIS_BROKER_PORT=6379
REDIS_BROKER_PASSWORD=redispassword123
# Optional, use a different redis database (defaults to 0)
# REDIS_BROKER_DB_INDEX=0
+# Alternatively specify the full redis url, i.e. if you need to use a unix:// socket
+# REDIS_BROKER_URL=
# Monitoring for celery
FLOWER_PORT=8888
diff --git a/bookwyrm/management/commands/erase_streams.py b/bookwyrm/management/commands/erase_streams.py
index 9d971d699..ecd36006c 100644
--- a/bookwyrm/management/commands/erase_streams.py
+++ b/bookwyrm/management/commands/erase_streams.py
@@ -4,12 +4,7 @@ import redis
from bookwyrm import settings
-r = redis.Redis(
- host=settings.REDIS_ACTIVITY_HOST,
- port=settings.REDIS_ACTIVITY_PORT,
- password=settings.REDIS_ACTIVITY_PASSWORD,
- db=settings.REDIS_ACTIVITY_DB_INDEX,
-)
+r = redis.from_url(settings.REDIS_ACTIVITY_URL)
def erase_streams():
diff --git a/bookwyrm/redis_store.py b/bookwyrm/redis_store.py
index ae50db2ee..f25829f5c 100644
--- a/bookwyrm/redis_store.py
+++ b/bookwyrm/redis_store.py
@@ -4,12 +4,7 @@ import redis
from bookwyrm import settings
-r = redis.Redis(
- host=settings.REDIS_ACTIVITY_HOST,
- port=settings.REDIS_ACTIVITY_PORT,
- password=settings.REDIS_ACTIVITY_PASSWORD,
- db=settings.REDIS_ACTIVITY_DB_INDEX,
-)
+r = redis.from_url(settings.REDIS_ACTIVITY_URL)
class RedisStore(ABC):
diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py
index 74ef7d313..99aae9694 100644
--- a/bookwyrm/settings.py
+++ b/bookwyrm/settings.py
@@ -11,7 +11,7 @@ from django.utils.translation import gettext_lazy as _
env = Env()
env.read_env()
DOMAIN = env("DOMAIN")
-VERSION = "0.5.3"
+VERSION = "0.5.4"
RELEASE_API = env(
"RELEASE_API",
@@ -21,7 +21,7 @@ RELEASE_API = env(
PAGE_LENGTH = env("PAGE_LENGTH", 15)
DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English")
-JS_CACHE = "ad848b97"
+JS_CACHE = "cd848b9a"
# email
EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend")
@@ -207,7 +207,10 @@ REDIS_ACTIVITY_HOST = env("REDIS_ACTIVITY_HOST", "localhost")
REDIS_ACTIVITY_PORT = env("REDIS_ACTIVITY_PORT", 6379)
REDIS_ACTIVITY_PASSWORD = env("REDIS_ACTIVITY_PASSWORD", None)
REDIS_ACTIVITY_DB_INDEX = env("REDIS_ACTIVITY_DB_INDEX", 0)
-
+REDIS_ACTIVITY_URL = env(
+ "REDIS_ACTIVITY_URL",
+ f"redis://:{REDIS_ACTIVITY_PASSWORD}@{REDIS_ACTIVITY_HOST}:{REDIS_ACTIVITY_PORT}/{REDIS_ACTIVITY_DB_INDEX}",
+)
MAX_STREAM_LENGTH = int(env("MAX_STREAM_LENGTH", 200))
STREAMS = [
@@ -232,7 +235,7 @@ else:
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
- "LOCATION": f"redis://:{REDIS_ACTIVITY_PASSWORD}@{REDIS_ACTIVITY_HOST}:{REDIS_ACTIVITY_PORT}/{REDIS_ACTIVITY_DB_INDEX}",
+ "LOCATION": REDIS_ACTIVITY_URL,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
diff --git a/bookwyrm/tests/test_signing.py b/bookwyrm/tests/test_signing.py
index 26d5e99a9..961e45435 100644
--- a/bookwyrm/tests/test_signing.py
+++ b/bookwyrm/tests/test_signing.py
@@ -35,6 +35,7 @@ Sender = namedtuple("Sender", ("remote_id", "key_pair"))
class Signature(TestCase):
"""signature test"""
+ # pylint: disable=invalid-name
def setUp(self):
"""create users and test data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
@@ -86,7 +87,7 @@ class Signature(TestCase):
data = json.dumps(get_follow_activity(sender, self.rat))
digest = digest or make_digest(data)
signature = make_signature(signer or sender, self.rat.inbox, now, digest)
- with patch("bookwyrm.views.inbox.activity_task.delay"):
+ with patch("bookwyrm.views.inbox.activity_task.apply_async"):
with patch("bookwyrm.models.user.set_remote_server.delay"):
return self.send(signature, now, send_data or data, digest)
diff --git a/bookwyrm/tests/views/books/test_edit_book.py b/bookwyrm/tests/views/books/test_edit_book.py
index 9e3f84a1b..2dc25095f 100644
--- a/bookwyrm/tests/views/books/test_edit_book.py
+++ b/bookwyrm/tests/views/books/test_edit_book.py
@@ -1,6 +1,7 @@
""" test for app action functionality """
from unittest.mock import patch
import responses
+from responses import matchers
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
@@ -45,6 +46,44 @@ class EditBookViews(TestCase):
remote_id="https://example.com/book/1",
parent_work=self.work,
)
+ # pylint: disable=line-too-long
+ self.authors_body = "1.10000000084510024"
+
+ # pylint: disable=line-too-long
+ self.author_body = "0000000084510024https://isni.org/isni/000000008451002460Catherine Amy Dawson Scottpoet and novelistpublicQ544961C. A.Dawson Scott1865-1934publica28927850VIAF45886165ALLCREhttp://viaf.org/viaf/45886165Wikipediahttps://en.wikipedia.org/wiki/Catherine_Amy_Dawson_Scott"
+
+ responses.get(
+ "http://isni.oclc.org/sru/",
+ content_type="text/xml",
+ match=[
+ matchers.query_param_matcher(
+ {"query": 'pica.na="Sappho"'}, strict_match=False
+ )
+ ],
+ body=self.authors_body,
+ )
+
+ responses.get(
+ "http://isni.oclc.org/sru/",
+ content_type="text/xml",
+ match=[
+ matchers.query_param_matcher(
+ {"query": 'pica.na="Some Guy"'}, strict_match=False
+ )
+ ],
+ body=self.authors_body,
+ )
+
+ responses.get(
+ "http://isni.oclc.org/sru/",
+ content_type="text/xml",
+ match=[
+ matchers.query_param_matcher(
+ {"query": 'pica.isn="0000000084510024"'}, strict_match=False
+ )
+ ],
+ body=self.author_body,
+ )
models.SiteSettings.objects.create()
@@ -97,6 +136,7 @@ class EditBookViews(TestCase):
result.context_data["cover_url"], "http://local.host/cover.jpg"
)
+ @responses.activate
def test_edit_book_add_author(self):
"""lets a user edit a book with new authors"""
view = views.EditBook.as_view()
@@ -227,6 +267,7 @@ class EditBookViews(TestCase):
self.book.refresh_from_db()
self.assertTrue(self.book.cover)
+ @responses.activate
def test_add_authors_helper(self):
"""converts form input into author matches"""
form = forms.EditionForm(instance=self.book)
diff --git a/bookwyrm/tests/views/inbox/test_inbox.py b/bookwyrm/tests/views/inbox/test_inbox.py
index e328b1ba4..61acde5d3 100644
--- a/bookwyrm/tests/views/inbox/test_inbox.py
+++ b/bookwyrm/tests/views/inbox/test_inbox.py
@@ -15,6 +15,7 @@ from bookwyrm import models, views
class Inbox(TestCase):
"""readthrough tests"""
+ # pylint: disable=invalid-name
def setUp(self):
"""basic user and book data"""
self.client = Client()
@@ -119,7 +120,7 @@ class Inbox(TestCase):
with patch("bookwyrm.views.inbox.has_valid_signature") as mock_valid:
mock_valid.return_value = True
- with patch("bookwyrm.views.inbox.activity_task.delay"):
+ with patch("bookwyrm.views.inbox.activity_task.apply_async"):
result = self.client.post(
"/inbox", json.dumps(activity), content_type="application/json"
)
diff --git a/bookwyrm/utils/isni.py b/bookwyrm/utils/isni.py
index ea0364e55..318de30ef 100644
--- a/bookwyrm/utils/isni.py
+++ b/bookwyrm/utils/isni.py
@@ -85,6 +85,9 @@ def find_authors_by_name(name_string, description=False):
# build list of possible authors
possible_authors = []
for element in root.iter("responseRecord"):
+
+ # TODO: we don't seem to do anything with the
+ # personal_name variable - is this code block needed?
personal_name = element.find(".//forename/..")
if not personal_name:
continue
diff --git a/bookwyrm/views/admin/celery_status.py b/bookwyrm/views/admin/celery_status.py
index 7da148a06..5221fd619 100644
--- a/bookwyrm/views/admin/celery_status.py
+++ b/bookwyrm/views/admin/celery_status.py
@@ -8,12 +8,7 @@ import redis
from celerywyrm import settings
from bookwyrm.tasks import app as celery
-r = redis.Redis(
- host=settings.REDIS_BROKER_HOST,
- port=settings.REDIS_BROKER_PORT,
- password=settings.REDIS_BROKER_PASSWORD,
- db=settings.REDIS_BROKER_DB_INDEX,
-)
+r = redis.from_url(settings.REDIS_BROKER_URL)
# pylint: disable= no-self-use
@method_decorator(login_required, name="dispatch")
diff --git a/bookwyrm/views/inbox.py b/bookwyrm/views/inbox.py
index eec35f9d1..747b5eccd 100644
--- a/bookwyrm/views/inbox.py
+++ b/bookwyrm/views/inbox.py
@@ -14,7 +14,7 @@ from django.views import View
from django.views.decorators.csrf import csrf_exempt
from bookwyrm import activitypub, models
-from bookwyrm.tasks import app, MEDIUM
+from bookwyrm.tasks import app, MEDIUM, HIGH
from bookwyrm.signatures import Signature
from bookwyrm.utils import regex
@@ -60,7 +60,11 @@ class Inbox(View):
return HttpResponse()
return HttpResponse(status=401)
- activity_task.delay(activity_json)
+ # Make activities relating to follow/unfollow a high priority
+ high = ["Follow", "Accept", "Reject", "Block", "Unblock", "Undo"]
+
+ priority = HIGH if activity_json["type"] in high else MEDIUM
+ activity_task.apply_async(args=(activity_json,), queue=priority)
return HttpResponse()
diff --git a/celerywyrm/settings.py b/celerywyrm/settings.py
index 94e530221..7519ea6e3 100644
--- a/celerywyrm/settings.py
+++ b/celerywyrm/settings.py
@@ -8,9 +8,13 @@ REDIS_BROKER_PASSWORD = requests.utils.quote(env("REDIS_BROKER_PASSWORD", None))
REDIS_BROKER_HOST = env("REDIS_BROKER_HOST", "redis_broker")
REDIS_BROKER_PORT = env("REDIS_BROKER_PORT", 6379)
REDIS_BROKER_DB_INDEX = env("REDIS_BROKER_DB_INDEX", 0)
+REDIS_BROKER_URL = env(
+ "REDIS_BROKER_URL",
+ f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB_INDEX}",
+)
-CELERY_BROKER_URL = f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB_INDEX}"
-CELERY_RESULT_BACKEND = f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB_INDEX}"
+CELERY_BROKER_URL = REDIS_BROKER_URL.replace("unix:", "redis+socket:")
+CELERY_RESULT_BACKEND = REDIS_BROKER_URL.replace("unix:", "redis+socket:")
CELERY_DEFAULT_QUEUE = "low_priority"
CELERY_CREATE_MISSING_QUEUES = True