render_messages: Use JSON Lines format.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-05-20 12:13:53 -07:00 committed by Tim Abbott
parent 9d290798eb
commit d1aa68994a
2 changed files with 6 additions and 7 deletions

View File

@ -1,6 +1,6 @@
from typing import Any
import ijson
import orjson
from django.core.management.base import BaseCommand, CommandParser
@ -18,7 +18,9 @@ class Command(BaseCommand):
total_count = 0
changed_count = 0
with open(options["dump1"]) as dump1, open(options["dump2"]) as dump2:
for m1, m2 in zip(ijson.items(dump1, "item"), ijson.items(dump2, "item")):
for line1, line2 in zip(dump1, dump2):
m1 = orjson.loads(line1)
m2 = orjson.loads(line2)
total_count += 1
if m1["id"] != m2["id"]:
self.stderr.write("Inconsistent messages dump")

View File

@ -38,7 +38,6 @@ class Command(BaseCommand):
os.makedirs(dest_dir)
with open(options["destination"], "wb") as result:
result.write(b"[")
messages = Message.objects.filter(id__gt=latest - amount, id__lte=latest).order_by("id")
for message in queryset_iterator(messages):
content = message.content
@ -59,9 +58,7 @@ class Command(BaseCommand):
{
"id": message.id,
"content": render_markdown(message, content),
}
},
option=orjson.OPT_APPEND_NEWLINE,
)
)
if message.id != latest:
result.write(b",")
result.write(b"]")