internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: bookwyrm-social/bookwyrm

Issue:
Cache busting for static files when changes need to be loaded
When the javascript is updates, there are usually a handful of users who experience broken behavior (#1284) because their browser is still working off a cached version of the previous one. I think using https://docs.djangoproject.com/en/3.2/ref/contrib/staticfiles/#django.contrib.staticfiles.storage.ManifestStaticFilesStorage will resolve this?


Discussion:

Resolving patch:
diff --git a/bookwyrm/context_processors.py b/bookwyrm/context_processors.py
--- a/bookwyrm/context_processors.py
+++ b/bookwyrm/context_processors.py
@@ -15,4 +15,5 @@ def site_settings(request):  # pylint: disable=unused-argument
         "media_full_url": settings.MEDIA_FULL_URL,
         "preview_images_enabled": settings.ENABLE_PREVIEW_IMAGES,
         "request_protocol": request_protocol,
+        "js_cache": settings.JS_CACHE,
     }
diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py
--- a/bookwyrm/settings.py
+++ b/bookwyrm/settings.py
@@ -13,6 +13,8 @@
 PAGE_LENGTH = env("PAGE_LENGTH", 15)
 DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English")
 
+JS_CACHE = "19447742"
+
 # email
 EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend")
 EMAIL_HOST = env("EMAIL_HOST")


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
OpenSearch provider support
**Is your feature request related to a problem? Please describe.**
Many sites like YouTube natively support [OpenSearch](https://developer.mozilla.org/en-US/docs/Web/OpenSearch) which enables users to add the site as a search provider for their browser. I use Firefox with lots of search provider plugins that allow me to search sites like StackOverflow, YouTube, GitHub etc with 1-click directly from my navigation bar, and I would like to search this website with 1-click too. 

**Describe the solution you'd like**
When going to any webpage on https://bookwyrm.social/ or any other instance, I should be able to add that instance as a search provider. 

**Describe alternatives you've considered**
N/A

**Additional context**
N/A


Discussion:

Resolving patch:
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py
--- a/bookwyrm/urls.py
+++ b/bookwyrm/urls.py
@@ -43,6 +43,7 @@
     re_path(r"^nodeinfo/2\.0/?$", views.nodeinfo),
     re_path(r"^api/v1/instance/?$", views.instance_info),
     re_path(r"^api/v1/instance/peers/?$", views.peers),
+    re_path(r"^opensearch.xml$", views.opensearch, name="opensearch"),
     # polling updates
     re_path("^api/updates/notifications/?$", views.get_notification_count),
     re_path("^api/updates/stream/(?P<stream>[a-z]+)/?$", views.get_unread_status_count),
diff --git a/bookwyrm/views/wellknown.py b/bookwyrm/views/wellknown.py
--- a/bookwyrm/views/wellknown.py
+++ b/bookwyrm/views/wellknown.py
@@ -130,3 +130,14 @@ def peers(_):
 def host_meta(request):
     """meta of the host"""
     return TemplateResponse(request, "host_meta.xml", {"DOMAIN": DOMAIN})
+
+
+@require_GET
+def opensearch(request):
+    """Open Search xml spec"""
+    site = models.SiteSettings.get()
+    logo_path = site.favicon or "images/favicon.png"
+    logo = f"{MEDIA_FULL_URL}{logo_path}"
+    return TemplateResponse(
+        request, "opensearch.xml", {"image": logo, "DOMAIN": DOMAIN}
+    )


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Unread statuses notification is often wrong
**Describe the bug**
In the home feed, It said that there are 9 unread statuses but there were only 2.

**To Reproduce**
Steps to reproduce the behavior:
1. https://bookwyrm.social/
2. Log in
3. Wait a few hours
4. Check back and see if the reported number matches with the actual number of statuses

**Expected behavior**
The right number in the notification.

**Instance**
bookwyrm.social

**Additional context**
There was at least 1 suspend + resume in between my 2 visits to the site.

---

**Desktop:**
    - OS: Gentoo Linux
    - Browser Firefox
    - Version 78.12.0esr (gentoo 1.0)


Discussion:
 This is so interesting, the first thing I thought of was that imports might be increasing the unread count but be too far backdated to appear on the timeline. Another low hanging fruit could be users composing and then deleting statuses.
Oh you know what, it may be including every save action on a status, which happens multiple times when a statuses is created for complicated reasons
It got worse. 😄 (There was no new status)

![screenshot: load 85 unread statuses](https://user-images.githubusercontent.com/3681516/129952293-dff34e24-1daa-41fe-a1bf-07e17fe820a9.png)

okay that must have been an import! but big hmmm about this feature for sure; I'll try and get it working better

Resolving patch:
diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py
--- a/bookwyrm/activitystreams.py
+++ b/bookwyrm/activitystreams.py
@@ -1,7 +1,9 @@
 """ access the activity streams stored in redis """
+from datetime import timedelta
 from django.dispatch import receiver
 from django.db import transaction
 from django.db.models import signals, Q
+from django.utils import timezone
 
 from bookwyrm import models
 from bookwyrm.redis_store import RedisStore, r
@@ -436,6 +438,10 @@ def remove_status_task(status_ids):
 def add_status_task(status_id, increment_unread=False):
     """add a status to any stream it should be in"""
     status = models.Status.objects.get(id=status_id)
+    # we don't want to tick the unread count for csv import statuses, idk how better
+    # to check than just to see if the states is more than a few days old
+    if status.created_date < timezone.now() - timedelta(days=2):
+        increment_unread = False
     for stream in streams.values():
         stream.add_status(status, increment_unread=increment_unread)
 


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Unable to post review in Safari on iPadOS
**Describe the bug**
When trying to post a long-ish review in Safari on iPadOS (desktop mode, content blockers disabled), the post button shows the spinner introduced with #1388, but the posting never concludes.

**To Reproduce**
Steps to reproduce the behavior:
1. Get an iPad pro 13.9” running iPadOS 14.7.1
2. Open your bookwyrm.social account in Safari, ensuring it runs in desktop mode and content blockers are disabled
3. Write a review of at least 2700 chars
4. Try to post it

**Expected behavior**
After some spinning, the review appears on your feed.

**Instance**
bookwyrm.social

**Extra context**
[Book I’m trying to review](https://bookwyrm.social/book/214201).

---

**Device Info:**
    - Device: iPad pro 2nd gen 13.9”
    - OS: iPadOS 14.7.1
    - Browser: Safari
    - Version N/A


Discussion:
Yikes, thank you for opening an issue! You're the second iOS user to report this problem. It's working fine for me on my Android phone and I don't have any iOS devices, so it's going to be a bit challenging for me to test this directly.

From what you're describing - it sounds like this is where it's hanging: https://github.com/bookwyrm-social/bookwyrm/blob/main/bookwyrm/static/js/status_cache.js#L72. There doesn't appear to be any compatibility issues with the fetch function (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#browser_compatibility).

Would it be possible for you to check the javascript console for an error (https://www.lifewire.com/activate-the-debug-console-in-safari-445798)? Having an error message would make it a lot easier to figure out where things are going awry.
Thanks for the pointer, I think I have found the issue: the console complains that `undefined is not an object` on [the line you identified](https://github.com/bookwyrm-social/bookwyrm/blob/main/bookwyrm/static/js/status_cache.js#L72), which can only mean that `trigger` is  undefined. As it turns out, Safari (desktop and iOS) does not support [`SubmitEvent`](http://developer.mozilla.org/en-US/docs/Web/API/SubmitEvent), so, yeah, this can’t work in Safari. At all.
(which is a pity, because the spinner and LocalStorage cached drafts are a huge step forward UX-wise)
Ah thank you so much! I should be able to have the form submit in the traditional way if the event trigger is populated correctly. I do have safari, happily, so I can properly debug this :)

Resolving patch:
diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py
--- a/bookwyrm/settings.py
+++ b/bookwyrm/settings.py
@@ -13,7 +13,7 @@
 PAGE_LENGTH = env("PAGE_LENGTH", 15)
 DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English")
 
-JS_CACHE = "19447742"
+JS_CACHE = "e5832a26"
 
 # email
 EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend")


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
POSTGRES_PORT isn't respected during server setup
**Describe the bug**
`POSTGRES_PORT` isn't respected - `docker-compose up --build` starts the postgres instance on port 5432 regardless.

**To Reproduce**
Steps to reproduce the behavior:
1. Follow the [documentation for setting up a new instance](https://docs.joinbookwyrm.com/installing-in-production.html)
2. In `.env`, set `POSTGRES_PORT` to `5433` (and make the corresponding changes in `docker-compose.yml`)
3. Run `docker-compose up --build`

**Expected behavior**
The database is started on port 5433

**Actual behavior**
The database is started on port 5432

**Additional context**
I also tried setting the fallback to `5433` in `bookwyrm/settings.py` in case something was going wrong with the env propagation, but that didn't help either.
I was finally able to workaround by additionally setting `PGPORT` in `.env`

---

**Server:**
    - OS: Raspberry Pi OS (raspbian) 10.4
    - docker 20.10.8
    - docker-compose 1.29.2



Discussion:

Resolving patch:
diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py
--- a/bookwyrm/settings.py
+++ b/bookwyrm/settings.py
@@ -127,7 +127,7 @@
         "USER": env("POSTGRES_USER", "fedireads"),
         "PASSWORD": env("POSTGRES_PASSWORD", "fedireads"),
         "HOST": env("POSTGRES_HOST", ""),
-        "PORT": env("POSTGRES_PORT", 5432),
+        "PORT": env("PGPORT", 5432),
     },
 }
 


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Pending follow requests still show up in suggested users
An additional signal is needed to remove users from suggestions when a follow request is created


Discussion:

Resolving patch:
diff --git a/bookwyrm/suggested_users.py b/bookwyrm/suggested_users.py
--- a/bookwyrm/suggested_users.py
+++ b/bookwyrm/suggested_users.py
@@ -148,6 +148,17 @@ def update_suggestions_on_follow(sender, instance, created, *args, **kwargs):
     rerank_user_task.delay(instance.user_object.id, update_only=False)
 
 
+@receiver(signals.post_save, sender=models.UserFollowRequest)
+# pylint: disable=unused-argument
+def update_suggestions_on_follow_request(sender, instance, created, *args, **kwargs):
+    """remove a follow from the recs and update the ranks"""
+    if not created or not instance.user_object.discoverable:
+        return
+
+    if instance.user_subject.local:
+        remove_suggestion_task.delay(instance.user_subject.id, instance.user_object.id)
+
+
 @receiver(signals.post_save, sender=models.UserBlocks)
 # pylint: disable=unused-argument
 def update_suggestions_on_block(sender, instance, *args, **kwargs):


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Book sorting in library (your books)
I have more than 300 books and the way they're sorted by default (guess it's by rating) doesn't make any sense to me personally.
For me sorting by date added would make more sense but it might well be by author for others or other criteria.


Discussion:
Agreed! It would be nice to have search as well. Right now it's ordered by the last updated date on the database join that places the book on the shelf -- not the most obvious :)

Resolving patch:
diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py
--- a/bookwyrm/settings.py
+++ b/bookwyrm/settings.py
@@ -7,6 +7,7 @@
 
 
 env = Env()
+env.read_env()
 DOMAIN = env("DOMAIN")
 VERSION = "0.0.1"
 
diff --git a/bookwyrm/views/shelf.py b/bookwyrm/views/shelf.py
--- a/bookwyrm/views/shelf.py
+++ b/bookwyrm/views/shelf.py
@@ -68,16 +68,30 @@ def get(self, request, username, shelf_identifier=None):
             deleted=False,
         ).order_by("-published_date")
 
+        reading = models.ReadThrough.objects
+
+        reading = reading.filter(user=user, book__id=OuterRef("id")).order_by(
+            "start_date"
+        )
+
         books = books.annotate(
             rating=Subquery(reviews.values("rating")[:1]),
             shelved_date=F("shelfbook__shelved_date"),
+            start_date=Subquery(reading.values("start_date")[:1]),
+            finish_date=Subquery(reading.values("finish_date")[:1]),
+            author=Subquery(
+                models.Book.objects.filter(id=OuterRef("id")).values("authors__name")[
+                    :1
+                ]
+            ),
         ).prefetch_related("authors")
 
+        books = sort_books(books, request.GET.get("sort"))
+
         paginated = Paginator(
-            books.order_by("-shelfbook__updated_date"),
+            books,
             PAGE_LENGTH,
         )
-
         page = paginated.get_page(request.GET.get("page"))
         data = {
             "user": user,
@@ -87,6 +101,7 @@ def get(self, request, username, shelf_identifier=None):
             "books": page,
             "edit_form": forms.ShelfForm(instance=shelf if shelf_identifier else None),
             "create_form": forms.ShelfForm(),
+            "sort": request.GET.get("sort"),
             "page_range": paginated.get_elided_page_range(
                 page.number, on_each_side=2, on_ends=1
             ),
@@ -207,3 +222,23 @@ def unshelve(request):
 
     shelf_book.delete()
     return redirect(request.headers.get("Referer", "/"))
+
+
+def sort_books(books, sort):
+    """Books in shelf sorting"""
+    sort_fields = [
+        "title",
+        "author",
+        "shelved_date",
+        "start_date",
+        "finish_date",
+        "rating",
+    ]
+
+    if sort in sort_fields:
+        books = books.order_by(sort)
+    elif sort and sort[1:] in sort_fields:
+        books = books.order_by(F(sort[1:]).desc(nulls_last=True))
+    else:
+        books = books.order_by("-shelved_date")
+    return books


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Some translation strings missing/not applied
**Describe the bug**
Some translations are not being applied.

**To Reproduce**

change Bookwyrm language to other than English (tested with Lithuanian)

https://ziurkes.group.lt/user/athinkingmeat/books/read
https://ziurkes.group.lt/user/athinkingmeat/books/reading
https://ziurkes.group.lt/user/athinkingmeat/books/to-read

**Expected behavior**
All these links should have "read", "currently reading" and "to read" strings translated, but they are shown in English

**Screenshots**

![image](https://user-images.githubusercontent.com/81133/143778383-c5e6f8b2-4925-4060-a886-e40b9b6361fb.png)

![image](https://user-images.githubusercontent.com/81133/143778390-5ba3cc06-6744-4a60-a855-27fb3202f690.png)

![image](https://user-images.githubusercontent.com/81133/143778375-e799c900-1737-4025-8d1e-80ea99b3df81.png)


**Instance**

https://ziurkes.group.lt/

**Additional context**
Probably is a problem with other languages as well



Discussion:
i am tracking production branch and i can see i have these files in my
instance

maybe some cache might interfere?

m


On Wed, Dec 01, 2021 at 03:17:45, Hugh Rundle ***@***.***>
wrote:

> This looks like the bug reported in #1566
> <https://github.com/bookwyrm-social/bookwyrm/issues/1566> and fixed in
> #1572 <https://github.com/bookwyrm-social/bookwyrm/pull/1572>.
>
> This fix was pulled into the production branch on 25 October so if
> ziurkes.group.lt hasn't been updated since then, doing an update to the
> latest production branch code should fix the issue.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/bookwyrm-social/bookwyrm/issues/1637#issuecomment-983190095>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAATZ3JE5E2UWSAE5HLYPETUOVZTTANCNFSM5I5QBZGA>
> .
>

It's not your cache, this is happening because of the way the shelf template is set up interacting with default shelf names. I'll take a look, we had to fix this in some other places as well.

Resolving patch:
diff --git a/bookwyrm/utils/isni.py b/bookwyrm/utils/isni.py
--- a/bookwyrm/utils/isni.py
+++ b/bookwyrm/utils/isni.py
@@ -19,7 +19,7 @@ def request_isni_data(search_index, search_term, max_records=5):
         "recordPacking": "xml",
         "sortKeys": "RLV,pica,0,,",
     }
-    result = requests.get("http://isni.oclc.org/sru/", params=query_params, timeout=10)
+    result = requests.get("http://isni.oclc.org/sru/", params=query_params, timeout=15)
     # the OCLC ISNI server asserts the payload is encoded
     # in latin1, but we know better
     result.encoding = "utf-8"


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Previews not loading correctly when using local image storage 
**Describe the bug**
Previews not loading correctly when using local image storage 

**To Reproduce**
In status update previews are not shown, for example:
https://ziurkes.group.lt/user/athinkingmeat/quotation/167#anchor-167
https://ziurkes.group.lt/user/athinkingmeat/review/166#anchor-166

**Expected behavior**
they work for books though:
https://ziurkes.group.lt/book/7

**Examples**
https://twitter.com/DievaiDemonai/status/1459865136781578243

**Instance**
https://ziurkes.group.lt/

**Additional context**
Using cloudflare and also caddy instead of nginx to serve files, but it seems that the variable is not generated in template itself, not that the file is not being served.






Discussion:

Resolving patch:
diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py
--- a/bookwyrm/views/feed.py
+++ b/bookwyrm/views/feed.py
@@ -177,12 +177,19 @@ def get(self, request, username, status_id):
             params=[status.id, visible_thread, visible_thread],
         )
 
+        preview = None
+        if hasattr(status, "book"):
+            preview = status.book.preview_image
+        elif status.mention_books.exists():
+            preview = status.mention_books.first().preview_image
+
         data = {
             **feed_page_data(request.user),
             **{
                 "status": status,
                 "children": children,
                 "ancestors": ancestors,
+                "preview": preview,
             },
         }
         return TemplateResponse(request, "feed/status.html", data)


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
button to add group lists from group page
**Is your feature request related to a problem? Please describe.**
At the moment if you want to add a group-curated list, you have to do it from the Lists page, rather than the home page of the Group. This makes sense if you know how the backend functionality works but is not very intuitive.

**Describe the solution you'd like**
  Add a `Create list` button (like the one in the lists view) to the Group page.

**Describe alternatives you've considered**
Leaving the current, obscure, functionality.

**Additional context**
I intended to add this once the initial group functionality was completed, but I forgot about it.
This Issue is to remind me to put in a PR to add this.



Discussion:

Resolving patch:
diff --git a/bookwyrm/views/group.py b/bookwyrm/views/group.py
--- a/bookwyrm/views/group.py
+++ b/bookwyrm/views/group.py
@@ -34,7 +34,8 @@ def get(self, request, group_id):
         data = {
             "group": group,
             "lists": lists,
-            "group_form": forms.GroupForm(instance=group),
+            "group_form": forms.GroupForm(instance=group, auto_id="group_form_id_%s"),
+            "list_form": forms.ListForm(),
             "path": "/group",
         }
         return TemplateResponse(request, "groups/group.html", data)
@@ -121,6 +122,11 @@ def get(self, request, group_id):
         """basic profile info"""
         user_query = request.GET.get("user_query")
         group = get_object_or_404(models.Group, id=group_id)
+        lists = (
+            models.List.privacy_filter(request.user)
+            .filter(group=group)
+            .order_by("-updated_date")
+        )
 
         if not group:
             return HttpResponseBadRequest()
@@ -142,7 +148,7 @@ def get(self, request, group_id):
             .filter(similarity__gt=0.5, local=True)
             .order_by("-similarity")[:5]
         )
-        data = {"no_results": not user_results}
+        no_results = not user_results
 
         if user_results.count() < 5:
             user_results = list(user_results) + suggested_users.get_suggestions(
@@ -151,8 +157,11 @@ def get(self, request, group_id):
 
         data = {
             "suggested_users": user_results,
+            "no_results": no_results,
             "group": group,
-            "group_form": forms.GroupForm(instance=group),
+            "lists": lists,
+            "group_form": forms.GroupForm(instance=group, auto_id="group_form_id_%s"),
+            "list_form": forms.ListForm(),
             "user_query": user_query,
             "requestor_is_manager": request.user == group.user,
         }


Test patch: