Merge branch 'main' into production

This commit is contained in:
Mouse Reeve 2024-04-04 17:19:41 -05:00
commit 09e53336c0
10 changed files with 117 additions and 31 deletions

View file

@ -139,14 +139,14 @@ class ActivityStream(RedisStore):
| ( | (
Q(following=status.user) & Q(following=status.reply_parent.user) Q(following=status.user) & Q(following=status.reply_parent.user)
) # if the user is following both authors ) # if the user is following both authors
).distinct() )
# only visible to the poster's followers and tagged users # only visible to the poster's followers and tagged users
elif status.privacy == "followers": elif status.privacy == "followers":
audience = audience.filter( audience = audience.filter(
Q(following=status.user) # if the user is following the author Q(following=status.user) # if the user is following the author
) )
return audience.distinct() return audience.distinct("id")
@tracer.start_as_current_span("ActivityStream.get_audience") @tracer.start_as_current_span("ActivityStream.get_audience")
def get_audience(self, status): def get_audience(self, status):
@ -156,7 +156,7 @@ class ActivityStream(RedisStore):
status_author = models.User.objects.filter( status_author = models.User.objects.filter(
is_active=True, local=True, id=status.user.id is_active=True, local=True, id=status.user.id
).values_list("id", flat=True) ).values_list("id", flat=True)
return list(set(list(audience) + list(status_author))) return list(set(audience) | set(status_author))
def get_stores_for_users(self, user_ids): def get_stores_for_users(self, user_ids):
"""convert a list of user ids into redis store ids""" """convert a list of user ids into redis store ids"""
@ -183,15 +183,13 @@ class HomeStream(ActivityStream):
def get_audience(self, status): def get_audience(self, status):
trace.get_current_span().set_attribute("stream_id", self.key) trace.get_current_span().set_attribute("stream_id", self.key)
audience = super()._get_audience(status) audience = super()._get_audience(status)
if not audience:
return []
# if the user is following the author # if the user is following the author
audience = audience.filter(following=status.user).values_list("id", flat=True) audience = audience.filter(following=status.user).values_list("id", flat=True)
# if the user is the post's author # if the user is the post's author
status_author = models.User.objects.filter( status_author = models.User.objects.filter(
is_active=True, local=True, id=status.user.id is_active=True, local=True, id=status.user.id
).values_list("id", flat=True) ).values_list("id", flat=True)
return list(set(list(audience) + list(status_author))) return list(set(audience) | set(status_author))
def get_statuses_for_user(self, user): def get_statuses_for_user(self, user):
return models.Status.privacy_filter( return models.Status.privacy_filter(
@ -239,9 +237,7 @@ class BooksStream(ActivityStream):
) )
audience = super()._get_audience(status) audience = super()._get_audience(status)
if not audience: return audience.filter(shelfbook__book__parent_work=work)
return models.User.objects.none()
return audience.filter(shelfbook__book__parent_work=work).distinct()
def get_audience(self, status): def get_audience(self, status):
# only show public statuses on the books feed, # only show public statuses on the books feed,

View file

@ -0,0 +1,19 @@
# Generated by Django 3.2.25 on 2024-04-03 19:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0199_status_bookwyrm_st_remote__06aeba_idx"),
]
operations = [
migrations.AddIndex(
model_name="status",
index=models.Index(
fields=["thread_id"], name="bookwyrm_st_thread__cf064f_idx"
),
),
]

View file

@ -0,0 +1,19 @@
# Generated by Django 3.2.25 on 2024-04-03 19:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0200_status_bookwyrm_st_thread__cf064f_idx"),
]
operations = [
migrations.AddIndex(
model_name="keypair",
index=models.Index(
fields=["remote_id"], name="bookwyrm_ke_remote__472927_idx"
),
),
]

View file

@ -0,0 +1,19 @@
# Generated by Django 3.2.25 on 2024-04-03 19:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0201_keypair_bookwyrm_ke_remote__472927_idx"),
]
operations = [
migrations.AddIndex(
model_name="user",
index=models.Index(
fields=["username"], name="bookwyrm_us_usernam_b2546d_idx"
),
),
]

View file

@ -0,0 +1,19 @@
# Generated by Django 3.2.25 on 2024-04-03 19:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0202_user_bookwyrm_us_usernam_b2546d_idx"),
]
operations = [
migrations.AddIndex(
model_name="user",
index=models.Index(
fields=["is_active", "local"], name="bookwyrm_us_is_acti_972dc4_idx"
),
),
]

View file

@ -82,6 +82,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
ordering = ("-published_date",) ordering = ("-published_date",)
indexes = [ indexes = [
models.Index(fields=["remote_id"]), models.Index(fields=["remote_id"]),
models.Index(fields=["thread_id"]),
] ]
def save(self, *args, **kwargs): def save(self, *args, **kwargs):

View file

@ -198,6 +198,14 @@ class User(OrderedCollectionPageMixin, AbstractUser):
hotp_secret = models.CharField(max_length=32, default=None, blank=True, null=True) hotp_secret = models.CharField(max_length=32, default=None, blank=True, null=True)
hotp_count = models.IntegerField(default=0, blank=True, null=True) hotp_count = models.IntegerField(default=0, blank=True, null=True)
class Meta(AbstractUser.Meta):
"""indexes"""
indexes = [
models.Index(fields=["username"]),
models.Index(fields=["is_active", "local"]),
]
@property @property
def active_follower_requests(self): def active_follower_requests(self):
"""Follow requests from active users""" """Follow requests from active users"""
@ -509,6 +517,13 @@ class KeyPair(ActivitypubMixin, BookWyrmModel):
activity_serializer = activitypub.PublicKey activity_serializer = activitypub.PublicKey
serialize_reverse_fields = [("owner", "owner", "id")] serialize_reverse_fields = [("owner", "owner", "id")]
class Meta:
"""indexes"""
indexes = [
models.Index(fields=["remote_id"]),
]
def get_remote_id(self): def get_remote_id(self):
# self.owner is set by the OneToOneField on User # self.owner is set by the OneToOneField on User
return f"{self.owner.remote_id}/#main-key" return f"{self.owner.remote_id}/#main-key"

View file

@ -64,7 +64,7 @@ server {
# directly serve static files from the # directly serve static files from the
# bookwyrm filesystem using sendfile. # bookwyrm filesystem using sendfile.
# make the logs quieter by not reporting these requests # make the logs quieter by not reporting these requests
location ~ ^/static/ { location /static/ {
root /app; root /app;
try_files $uri =404; try_files $uri =404;
add_header X-Cache-Status STATIC; add_header X-Cache-Status STATIC;
@ -72,15 +72,14 @@ server {
} }
# same with image files not in static folder # same with image files not in static folder
location ~ \.(bmp|ico|jpg|jpeg|png|svg|tif|tiff|webp)$ { location /images/ {
root /app; location ~ \.(bmp|ico|jpg|jpeg|png|svg|tif|tiff|webp)$ {
try_files $uri =404; root /app;
add_header X-Cache-Status STATIC; try_files $uri =404;
access_log off; add_header X-Cache-Status STATIC;
} access_log off;
}
# block access to any non-image files from images # block access to any non-image files from images
location ~ ^/images/ {
return 403; return 403;
} }

View file

@ -96,23 +96,22 @@ server {
# # directly serve static files from the # # directly serve static files from the
# # bookwyrm filesystem using sendfile. # # bookwyrm filesystem using sendfile.
# # make the logs quieter by not reporting these requests # # make the logs quieter by not reporting these requests
# location ~ ^/static/ { # location /static/ {
# root /app; # root /app;
# try_files $uri =404; # try_files $uri =404;
# add_header X-Cache-Status STATIC; # add_header X-Cache-Status STATIC;
# access_log off; # access_log off;
# } # }
#
# # same with image files not in static folder # # same with image files not in static folder
# location ~ \.(bmp|ico|jpg|jpeg|png|svg|tif|tiff|webp)$ { # location /images/ {
# root /app; # location ~ \.(bmp|ico|jpg|jpeg|png|svg|tif|tiff|webp)$ {
# try_files $uri =404; # root /app;
# add_header X-Cache-Status STATIC; # try_files $uri =404;
# access_log off; # add_header X-Cache-Status STATIC;
# } # access_log off;
# }
# # block access to any non-image files from images # # block access to any non-image files from images
# location ~ ^/images/ {
# return 403; # return 403;
# } # }
# #

View file

@ -28,7 +28,7 @@ opentelemetry-instrumentation-django==0.37b0
opentelemetry-instrumentation-psycopg2==0.37b0 opentelemetry-instrumentation-psycopg2==0.37b0
opentelemetry-sdk==1.16.0 opentelemetry-sdk==1.16.0
packaging==21.3 packaging==21.3
Pillow==10.2.0 Pillow==10.3.0
protobuf==3.20.* protobuf==3.20.*
psycopg2==2.9.5 psycopg2==2.9.5
pycryptodome==3.19.1 pycryptodome==3.19.1