Просмотр исходного кода

Management cmds for forums&threads sync

Rafał Pitoń 10 лет назад
Родитель
Сommit
74c05e4fa3

+ 0 - 0
misago/forums/management/__init__.py


+ 0 - 0
misago/forums/management/commands/__init__.py


+ 28 - 0
misago/forums/management/commands/synchronizeforums.py

@@ -0,0 +1,28 @@
+from django.core.management.base import BaseCommand
+
+from misago.core.management.progressbar import show_progress
+
+from misago.forums.models import Forum
+
+
+class Command(BaseCommand):
+    help = 'Synchronizes forums'
+
+    def handle(self, *args, **options):
+        forums_to_sync = Forum.objects.count()
+
+        message = 'Synchronizing %s forums...\n'
+        self.stdout.write(message % forums_to_sync)
+
+        message = '\n\nSynchronized %s forums'
+
+        synchronized_count = 0
+        show_progress(self, synchronized_count, forums_to_sync)
+        for forum in Forum.objects.iterator():
+            forum.synchronize()
+            forum.save()
+
+            synchronized_count += 1
+            show_progress(self, synchronized_count, forums_to_sync)
+
+        self.stdout.write(message % synchronized_count)

+ 0 - 0
misago/threads/management/__init__.py


+ 0 - 0
misago/threads/management/commands/__init__.py


+ 33 - 0
misago/threads/management/commands/synchronizethreads.py

@@ -0,0 +1,33 @@
+import time
+
+from django.core.management.base import BaseCommand
+
+from misago.core.management.progressbar import show_progress
+from misago.core.pgutils import batch_update
+
+from misago.threads.models import Thread
+
+
+class Command(BaseCommand):
+    help = 'Synchronizes threads'
+
+    def handle(self, *args, **options):
+        threads_to_sync = Thread.objects.count()
+
+        message = 'Synchronizing %s threads...\n'
+        self.stdout.write(message % threads_to_sync)
+
+        message = '\n\nSynchronized %s threads'
+
+        synchronized_count = 0
+        show_progress(self, synchronized_count, threads_to_sync)
+        start_time = time.time()
+        for thread in batch_update(Thread.objects.all()):
+            thread.synchronize()
+            thread.save()
+
+            synchronized_count += 1
+            show_progress(
+                self, synchronized_count, threads_to_sync, start_time)
+
+        self.stdout.write(message % synchronized_count)