mirror of https://github.com/zulip/zulip.git
render_messages: Use JSON Lines format.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
9d290798eb
commit
d1aa68994a
|
@ -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")
|
||||
|
|
|
@ -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"]")
|
||||
|
|
Loading…
Reference in New Issue