123456789101112131415161718192021222324252627282930313233343536373839 |
- from misago.core.pgutils import batch_update
- from ...models import MovedId, OldIdRedirect
- from ..base import BaseCommand
- MAPPINGS = {
- 'category': OldIdRedirect.CATEGORY,
- 'post': OldIdRedirect.POST,
- 'thread': OldIdRedirect.THREAD,
- 'user': OldIdRedirect.USER,
- }
- class Command(BaseCommand):
- help = (
- "Builds moves index for redirects from old urls to new ones."
- )
- def handle(self, *args, **options):
- self.stdout.write("Building moves index...")
- counter = 1
- self.start_timer()
- for moved_id in batch_update(MovedId.objects):
- counter += 1
- if moved_id.model not in MAPPINGS:
- continue
- OldIdRedirect.objects.create(
- model=MAPPINGS[moved_id.model],
- old_id=moved_id.old_id,
- new_id=moved_id.new_id,
- )
- summary = "Indexed %s items in %s" % (counter, self.stop_timer())
- self.stdout.write(self.style.SUCCESS(summary))
|