2021-03-28 18:38:39 +00:00
|
|
|
""" Re-create user streams """
|
2021-03-23 20:23:35 +00:00
|
|
|
from django.core.management.base import BaseCommand
|
2021-05-22 23:10:11 +00:00
|
|
|
from bookwyrm import activitystreams, models
|
2021-03-23 20:23:35 +00:00
|
|
|
|
2021-03-23 20:28:05 +00:00
|
|
|
|
2021-08-08 00:38:07 +00:00
|
|
|
def populate_streams(stream=None):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""build all the streams for all the users"""
|
2021-08-08 00:38:07 +00:00
|
|
|
streams = [stream] if stream else activitystreams.streams.keys()
|
2021-12-17 06:14:52 +00:00
|
|
|
print("Populating streams", streams)
|
2021-03-23 20:23:35 +00:00
|
|
|
users = models.User.objects.filter(
|
|
|
|
local=True,
|
|
|
|
is_active=True,
|
2021-08-08 00:38:07 +00:00
|
|
|
).order_by("-last_active_date")
|
|
|
|
print("This may take a long time! Please be patient.")
|
2021-03-23 20:23:35 +00:00
|
|
|
for user in users:
|
2021-08-08 00:38:07 +00:00
|
|
|
for stream_key in streams:
|
|
|
|
print(".", end="")
|
|
|
|
activitystreams.populate_stream_task.delay(stream_key, user.id)
|
2021-03-23 20:23:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""start all over with user streams"""
|
2021-03-23 20:23:35 +00:00
|
|
|
|
2021-03-28 18:38:39 +00:00
|
|
|
help = "Populate streams for all users"
|
2021-08-08 00:38:07 +00:00
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument(
|
|
|
|
"--stream",
|
|
|
|
default=None,
|
|
|
|
help="Specifies which time of stream to populate",
|
|
|
|
)
|
|
|
|
|
2021-03-23 20:23:35 +00:00
|
|
|
# pylint: disable=no-self-use,unused-argument
|
|
|
|
def handle(self, *args, **options):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""run feed builder"""
|
2021-08-08 00:38:07 +00:00
|
|
|
stream = options.get("stream")
|
|
|
|
populate_streams(stream=stream)
|