diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 754b4b15..0a90c9f4 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -4,7 +4,7 @@ from django.db.models import signals, Q from bookwyrm import models from bookwyrm.redis_store import RedisStore, r -from bookwyrm.settings import STREAMS +from bookwyrm.tasks import app from bookwyrm.views.helpers import privacy_filter @@ -56,7 +56,13 @@ class ActivityStream(RedisStore): return ( models.Status.objects.select_subclasses() .filter(id__in=statuses) - .select_related("user", "reply_parent") + .select_related( + "user", + "reply_parent", + "comment__book", + "review__book", + "quotation__book", + ) .prefetch_related("mention_books", "mention_users") .order_by("-published_date") ) @@ -235,15 +241,10 @@ class BooksStream(ActivityStream): # determine which streams are enabled in settings.py -available_streams = [s["key"] for s in STREAMS] streams = { - k: v - for (k, v) in { - "home": HomeStream(), - "local": LocalStream(), - "books": BooksStream(), - }.items() - if k in available_streams + "home": HomeStream(), + "local": LocalStream(), + "books": BooksStream(), } @@ -391,3 +392,11 @@ def remove_statuses_on_unshelve(sender, instance, *args, **kwargs): return BooksStream().remove_book_statuses(instance.user, instance.book) + + +@app.task +def populate_stream_task(stream, user_id): + """background task for populating an empty activitystream""" + user = models.User.objects.get(id=user_id) + stream = streams[stream] + stream.populate_streams(user) diff --git a/bookwyrm/management/commands/populate_streams.py b/bookwyrm/management/commands/populate_streams.py index f8aa21a5..a04d7f5a 100644 --- a/bookwyrm/management/commands/populate_streams.py +++ b/bookwyrm/management/commands/populate_streams.py @@ -3,22 +3,35 @@ from django.core.management.base import BaseCommand from bookwyrm import activitystreams, models -def populate_streams(): +def populate_streams(stream=None): """build all the streams for all the users""" + streams = [stream] if stream else activitystreams.streams.keys() + print("Populations streams", streams) users = models.User.objects.filter( local=True, is_active=True, - ) + ).order_by("-last_active_date") + print("This may take a long time! Please be patient.") for user in users: - for stream in activitystreams.streams.values(): - stream.populate_streams(user) + for stream_key in streams: + print(".", end="") + activitystreams.populate_stream_task.delay(stream_key, user.id) class Command(BaseCommand): """start all over with user streams""" help = "Populate streams for all users" + + def add_arguments(self, parser): + parser.add_argument( + "--stream", + default=None, + help="Specifies which time of stream to populate", + ) + # pylint: disable=no-self-use,unused-argument def handle(self, *args, **options): """run feed builder""" - populate_streams() + stream = options.get("stream") + populate_streams(stream=stream) diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index d10fb9b7..8fbdcfc6 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -29,6 +29,11 @@ body { min-width: 75% !important; } +.clip-text { + max-height: 35em; + overflow: hidden; +} + /** Utilities not covered by Bulma ******************************************************************************/ diff --git a/bookwyrm/templates/discover/discover.html b/bookwyrm/templates/discover/discover.html index d553c368..01ef2186 100644 --- a/bookwyrm/templates/discover/discover.html +++ b/bookwyrm/templates/discover/discover.html @@ -1,50 +1,89 @@ -{% extends 'discover/landing_layout.html' %} +{% extends "layout.html" %} {% load i18n %} -{% block panel %} -
+ {% blocktrans trimmed with site_name=site.name %} + See what's new in the local {{ site_name }} community + {% endblocktrans %} +
++ {% trans "by" %} + {% include 'snippets/authors.html' with limit=3 %} +
+ {% endif %} -- {% trans "by" %} - {% include 'snippets/authors.html' %} -
- {% endif %} - - {% if book|book_description %} -- {{ book|book_description|to_markdown|safe|truncatewords_html:50 }} -- {% endif %} -
- {% trans "by" %} - {% include 'snippets/authors.html' %} + {% include 'snippets/stars.html' with rating=status.rating %}
- {% endif %} - {% endwith %} + {% endif %} ++ {% trans "by" %} + {% include 'snippets/authors.html' with limit=3 %} +
+ {% endif %} + + {% if book|book_description %} ++ {{ book|book_description|to_markdown|safe|truncatewords_html:50 }} ++ {% endif %} +
+ {% trans "by" %} + {% include 'snippets/authors.html' with limit=3 %} +
+ {% endif %} + {% endwith %} +{% endif %} diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index c215648f..6d050097 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -67,8 +67,8 @@ {% trans "Lists" %} - - {% trans "Directory" %} + + {% trans "Discover" %} {% endif %}