Adds management and bw-dev commands

This commit is contained in:
Mouse Reeve 2021-11-16 10:41:08 -08:00
parent 1d28c7e73d
commit 903aaaf4c4
3 changed files with 41 additions and 2 deletions

View file

@ -0,0 +1,34 @@
""" Re-create user streams """
from django.core.management.base import BaseCommand
from bookwyrm import lists_stream, models
def populate_lists_streams():
"""build all the lists streams for all the users"""
print("Populating lists 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:
print(".", end="")
lists_stream.populate_lists_stream_task.delay(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_lists_streams()

View file

@ -1,18 +1,20 @@
""" Re-create user streams """ """ Re-create user streams """
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from bookwyrm import activitystreams, models from bookwyrm import activitystreams, lists_stream, models
def populate_streams(stream=None): def populate_streams(stream=None):
"""build all the streams for all the users""" """build all the streams for all the users"""
streams = [stream] if stream else activitystreams.streams.keys() streams = [stream] if stream else activitystreams.streams.keys()
print("Populations streams", streams) print("Populating streams", streams)
users = models.User.objects.filter( users = models.User.objects.filter(
local=True, local=True,
is_active=True, is_active=True,
).order_by("-last_active_date") ).order_by("-last_active_date")
print("This may take a long time! Please be patient.") print("This may take a long time! Please be patient.")
for user in users: for user in users:
print(".", end="")
lists_stream.populate_lists_stream_task.delay(user.id)
for stream_key in streams: for stream_key in streams:
print(".", end="") print(".", end="")
activitystreams.populate_stream_task.delay(stream_key, user.id) activitystreams.populate_stream_task.delay(stream_key, user.id)

3
bw-dev
View file

@ -120,6 +120,9 @@ case "$CMD" in
populate_streams) populate_streams)
runweb python manage.py populate_streams $@ runweb python manage.py populate_streams $@
;; ;;
populate_lists_streams)
runweb python manage.py populate_lists_streams $@
;;
populate_suggestions) populate_suggestions)
runweb python manage.py populate_suggestions runweb python manage.py populate_suggestions
;; ;;