prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Most Beloved Book on Instance has zero local reviews
  **Describe the bug**
  On the About this Instance page there's a cool section that shows various books, like Most Beloved, Most Contentious, Most Wanted to Read. The Most Beloved category, however, appears to be driven by federated statistics and not local statistics. A book with no local ratings is listed as the most Beloved Book because *other* instances have rated it highly. 
  
  **To Reproduce**
  Steps to reproduce the behavior:
  1. Don't have a lot of ratings on your instance.
  2. Import a book that is highly rated from another (in this case 3 reviews, all 5 stars) 
  3. Go to instancedomain/about and view the Most Beloved book
  
  I'm really only guessing on these steps to reproduce, it's just something I stumbled across.
  
  **Expected behavior**
  I expect the most beloved book to be beloved by my instance, not other instances. Federated statistics would also be cool, but it doesn't seem like this section is meant to represent the network. 
  
  **Instance**
  https://tankie.ml/
  
  ---
  
  **Smartphone (please complete the following information):**
      - Device: Samsung Galaxy A52 5G
      - OS: Android 12
      - Browser: Firefox
      - Version: 97.2.0
      
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `bookwyrm/templatetags/landing_page_tags.py`
  Content:
  ```
  1 """ template filters """
  2 from django import template
  3 from django.db.models import Avg, StdDev, Count, F, Q
  4 
  5 from bookwyrm import models
  6 
  7 register = template.Library()
  8 
  9 
  10 @register.simple_tag(takes_context=False)
  11 def get_book_superlatives():
  12     """get book stats for the about page"""
  13     total_ratings = models.Review.objects.filter(local=True, deleted=False).count()
  14     data = {}
  15     data["top_rated"] = (
  16         models.Work.objects.annotate(
  17             rating=Avg(
  18                 "editions__review__rating",
  19                 filter=Q(editions__review__local=True, editions__review__deleted=False),
  20             ),
  21             rating_count=Count(
  22                 "editions__review",
  23                 filter=Q(editions__review__local=True, editions__review__deleted=False),
  24             ),
  25         )
  26         .annotate(weighted=F("rating") * F("rating_count") / total_ratings)
  27         .filter(rating__gt=4, weighted__gt=0)
  28         .order_by("-weighted")
  29         .first()
  30     )
  31 
  32     data["controversial"] = (
  33         models.Work.objects.annotate(
  34             deviation=StdDev(
  35                 "editions__review__rating",
  36                 filter=Q(editions__review__local=True, editions__review__deleted=False),
  37             ),
  38             rating_count=Count(
  39                 "editions__review",
  40                 filter=Q(editions__review__local=True, editions__review__deleted=False),
  41             ),
  42         )
  43         .annotate(weighted=F("deviation") * F("rating_count") / total_ratings)
  44         .filter(weighted__gt=0)
  45         .order_by("-weighted")
  46         .first()
  47     )
  48 
  49     data["wanted"] = (
  50         models.Work.objects.annotate(
  51             shelf_count=Count(
  52                 "editions__shelves", filter=Q(editions__shelves__identifier="to-read")
  53             )
  54         )
  55         .order_by("-shelf_count")
  56         .first()
  57     )
  58     return data
  59 
  60 
  61 @register.simple_tag(takes_context=False)
  62 def get_landing_books():
  63     """list of books for the landing page"""
  64     return list(
  65         set(
  66             models.Edition.objects.filter(
  67                 review__published_date__isnull=False,
  68                 review__deleted=False,
  69                 review__user__local=True,
  70                 review__privacy__in=["public", "unlisted"],
  71             )
  72             .exclude(cover__exact="")
  73             .distinct()
  74             .order_by("-review__published_date")[:6]
  75         )
  76     )
  77
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/bookwyrm/templatetags/landing_page_tags.py b/bookwyrm/templatetags/landing_page_tags.py
  --- a/bookwyrm/templatetags/landing_page_tags.py
  +++ b/bookwyrm/templatetags/landing_page_tags.py
  @@ -16,11 +16,15 @@
           models.Work.objects.annotate(
               rating=Avg(
                   "editions__review__rating",
  -                filter=Q(editions__review__local=True, editions__review__deleted=False),
  +                filter=Q(
  +                    editions__review__user__local=True, editions__review__deleted=False
  +                ),
               ),
               rating_count=Count(
                   "editions__review",
  -                filter=Q(editions__review__local=True, editions__review__deleted=False),
  +                filter=Q(
  +                    editions__review__user__local=True, editions__review__deleted=False
  +                ),
               ),
           )
           .annotate(weighted=F("rating") * F("rating_count") / total_ratings)
  @@ -33,11 +37,15 @@
           models.Work.objects.annotate(
               deviation=StdDev(
                   "editions__review__rating",
  -                filter=Q(editions__review__local=True, editions__review__deleted=False),
  +                filter=Q(
  +                    editions__review__user__local=True, editions__review__deleted=False
  +                ),
               ),
               rating_count=Count(
                   "editions__review",
  -                filter=Q(editions__review__local=True, editions__review__deleted=False),
  +                filter=Q(
  +                    editions__review__user__local=True, editions__review__deleted=False
  +                ),
               ),
           )
           .annotate(weighted=F("deviation") * F("rating_count") / total_ratings)
  
verification_info: {"golden_diff": "diff --git a/bookwyrm/templatetags/landing_page_tags.py b/bookwyrm/templatetags/landing_page_tags.py\n--- a/bookwyrm/templatetags/landing_page_tags.py\n+++ b/bookwyrm/templatetags/landing_page_tags.py\n@@ -16,11 +16,15 @@\n         models.Work.objects.annotate(\n             rating=Avg(\n                 \"editions__review__rating\",\n-                filter=Q(editions__review__local=True, editions__review__deleted=False),\n+                filter=Q(\n+                    editions__review__user__local=True, editions__review__deleted=False\n+                ),\n             ),\n             rating_count=Count(\n                 \"editions__review\",\n-                filter=Q(editions__review__local=True, editions__review__deleted=False),\n+                filter=Q(\n+                    editions__review__user__local=True, editions__review__deleted=False\n+                ),\n             ),\n         )\n         .annotate(weighted=F(\"rating\") * F(\"rating_count\") / total_ratings)\n@@ -33,11 +37,15 @@\n         models.Work.objects.annotate(\n             deviation=StdDev(\n                 \"editions__review__rating\",\n-                filter=Q(editions__review__local=True, editions__review__deleted=False),\n+                filter=Q(\n+                    editions__review__user__local=True, editions__review__deleted=False\n+                ),\n             ),\n             rating_count=Count(\n                 \"editions__review\",\n-                filter=Q(editions__review__local=True, editions__review__deleted=False),\n+                filter=Q(\n+                    editions__review__user__local=True, editions__review__deleted=False\n+                ),\n             ),\n         )\n         .annotate(weighted=F(\"deviation\") * F(\"rating_count\") / total_ratings)\n", "issue": "Most Beloved Book on Instance has zero local reviews\n**Describe the bug**\nOn the About this Instance page there's a cool section that shows various books, like Most Beloved, Most Contentious, Most Wanted to Read. The Most Beloved category, however, appears to be driven by federated statistics and not local statistics. A book with no local ratings is listed as the most Beloved Book because *other* instances have rated it highly. \n\n**To Reproduce**\nSteps to reproduce the behavior:\n1. Don't have a lot of ratings on your instance.\n2. Import a book that is highly rated from another (in this case 3 reviews, all 5 stars) \n3. Go to instancedomain/about and view the Most Beloved book\n\nI'm really only guessing on these steps to reproduce, it's just something I stumbled across.\n\n**Expected behavior**\nI expect the most beloved book to be beloved by my instance, not other instances. Federated statistics would also be cool, but it doesn't seem like this section is meant to represent the network. \n\n**Instance**\nhttps://tankie.ml/\n\n---\n\n**Smartphone (please complete the following information):**\n    - Device: Samsung Galaxy A52 5G\n    - OS: Android 12\n    - Browser: Firefox\n    - Version: 97.2.0\n    \n", "before_files": [{"content": "\"\"\" template filters \"\"\"\nfrom django import template\nfrom django.db.models import Avg, StdDev, Count, F, Q\n\nfrom bookwyrm import models\n\nregister = template.Library()\n\n\n@register.simple_tag(takes_context=False)\ndef get_book_superlatives():\n    \"\"\"get book stats for the about page\"\"\"\n    total_ratings = models.Review.objects.filter(local=True, deleted=False).count()\n    data = {}\n    data[\"top_rated\"] = (\n        models.Work.objects.annotate(\n            rating=Avg(\n                \"editions__review__rating\",\n                filter=Q(editions__review__local=True, editions__review__deleted=False),\n            ),\n            rating_count=Count(\n                \"editions__review\",\n                filter=Q(editions__review__local=True, editions__review__deleted=False),\n            ),\n        )\n        .annotate(weighted=F(\"rating\") * F(\"rating_count\") / total_ratings)\n        .filter(rating__gt=4, weighted__gt=0)\n        .order_by(\"-weighted\")\n        .first()\n    )\n\n    data[\"controversial\"] = (\n        models.Work.objects.annotate(\n            deviation=StdDev(\n                \"editions__review__rating\",\n                filter=Q(editions__review__local=True, editions__review__deleted=False),\n            ),\n            rating_count=Count(\n                \"editions__review\",\n                filter=Q(editions__review__local=True, editions__review__deleted=False),\n            ),\n        )\n        .annotate(weighted=F(\"deviation\") * F(\"rating_count\") / total_ratings)\n        .filter(weighted__gt=0)\n        .order_by(\"-weighted\")\n        .first()\n    )\n\n    data[\"wanted\"] = (\n        models.Work.objects.annotate(\n            shelf_count=Count(\n                \"editions__shelves\", filter=Q(editions__shelves__identifier=\"to-read\")\n            )\n        )\n        .order_by(\"-shelf_count\")\n        .first()\n    )\n    return data\n\n\n@register.simple_tag(takes_context=False)\ndef get_landing_books():\n    \"\"\"list of books for the landing page\"\"\"\n    return list(\n        set(\n            models.Edition.objects.filter(\n                review__published_date__isnull=False,\n                review__deleted=False,\n                review__user__local=True,\n                review__privacy__in=[\"public\", \"unlisted\"],\n            )\n            .exclude(cover__exact=\"\")\n            .distinct()\n            .order_by(\"-review__published_date\")[:6]\n        )\n    )\n", "path": "bookwyrm/templatetags/landing_page_tags.py"}], "after_files": [{"content": "\"\"\" template filters \"\"\"\nfrom django import template\nfrom django.db.models import Avg, StdDev, Count, F, Q\n\nfrom bookwyrm import models\n\nregister = template.Library()\n\n\n@register.simple_tag(takes_context=False)\ndef get_book_superlatives():\n    \"\"\"get book stats for the about page\"\"\"\n    total_ratings = models.Review.objects.filter(local=True, deleted=False).count()\n    data = {}\n    data[\"top_rated\"] = (\n        models.Work.objects.annotate(\n            rating=Avg(\n                \"editions__review__rating\",\n                filter=Q(\n                    editions__review__user__local=True, editions__review__deleted=False\n                ),\n            ),\n            rating_count=Count(\n                \"editions__review\",\n                filter=Q(\n                    editions__review__user__local=True, editions__review__deleted=False\n                ),\n            ),\n        )\n        .annotate(weighted=F(\"rating\") * F(\"rating_count\") / total_ratings)\n        .filter(rating__gt=4, weighted__gt=0)\n        .order_by(\"-weighted\")\n        .first()\n    )\n\n    data[\"controversial\"] = (\n        models.Work.objects.annotate(\n            deviation=StdDev(\n                \"editions__review__rating\",\n                filter=Q(\n                    editions__review__user__local=True, editions__review__deleted=False\n                ),\n            ),\n            rating_count=Count(\n                \"editions__review\",\n                filter=Q(\n                    editions__review__user__local=True, editions__review__deleted=False\n                ),\n            ),\n        )\n        .annotate(weighted=F(\"deviation\") * F(\"rating_count\") / total_ratings)\n        .filter(weighted__gt=0)\n        .order_by(\"-weighted\")\n        .first()\n    )\n\n    data[\"wanted\"] = (\n        models.Work.objects.annotate(\n            shelf_count=Count(\n                \"editions__shelves\", filter=Q(editions__shelves__identifier=\"to-read\")\n            )\n        )\n        .order_by(\"-shelf_count\")\n        .first()\n    )\n    return data\n\n\n@register.simple_tag(takes_context=False)\ndef get_landing_books():\n    \"\"\"list of books for the landing page\"\"\"\n    return list(\n        set(\n            models.Edition.objects.filter(\n                review__published_date__isnull=False,\n                review__deleted=False,\n                review__user__local=True,\n                review__privacy__in=[\"public\", \"unlisted\"],\n            )\n            .exclude(cover__exact=\"\")\n            .distinct()\n            .order_by(\"-review__published_date\")[:6]\n        )\n    )\n", "path": "bookwyrm/templatetags/landing_page_tags.py"}]}