synchronizethreads.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import time
  2. from django.core.management.base import BaseCommand
  3. from misago.core.management.progressbar import show_progress
  4. from misago.core.pgutils import chunk_queryset
  5. from misago.threads.models import Thread
  6. class Command(BaseCommand):
  7. help = "Synchronizes threads"
  8. def handle(self, *args, **options):
  9. threads_to_sync = Thread.objects.count()
  10. if not threads_to_sync:
  11. self.stdout.write("\n\nNo threads were found")
  12. else:
  13. self.sync_threads(threads_to_sync)
  14. def sync_threads(self, threads_to_sync):
  15. self.stdout.write("Synchronizing {} threads...\n".format(threads_to_sync))
  16. synchronized_count = 0
  17. show_progress(self, synchronized_count, threads_to_sync)
  18. start_time = time.time()
  19. for thread in chunk_queryset(Thread.objects.all()):
  20. thread.synchronize()
  21. thread.save()
  22. synchronized_count += 1
  23. show_progress(self, synchronized_count, threads_to_sync, start_time)
  24. self.stdout.write("\n\nSynchronized {} threads".format(synchronized_count))