synchronizethreads.py 960 B

123456789101112131415161718192021222324252627282930313233
  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 batch_update
  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. message = 'Synchronizing %s threads...\n'
  11. self.stdout.write(message % threads_to_sync)
  12. message = '\n\nSynchronized %s threads'
  13. synchronized_count = 0
  14. show_progress(self, synchronized_count, threads_to_sync)
  15. start_time = time.time()
  16. for thread in batch_update(Thread.objects.all()):
  17. thread.synchronize()
  18. thread.save()
  19. synchronized_count += 1
  20. show_progress(
  21. self, synchronized_count, threads_to_sync, start_time)
  22. self.stdout.write(message % synchronized_count)