mirror of https://github.com/zulip/zulip.git
dump_pointers: Use timestamps, not IDs, for transmitting the pointer.
(imported from commit 9b51b9edc5b0bdfb2305c12a123d554811ec9e06)
This commit is contained in:
parent
bda420a0f9
commit
e330be7fc1
|
@ -1,17 +1,28 @@
|
|||
from optparse import make_option
|
||||
from django.core.management.base import BaseCommand
|
||||
from zephyr.models import Realm, UserProfile
|
||||
from zephyr.models import Realm, UserProfile, Message
|
||||
from zephyr.lib.time import datetime_to_timestamp, timestamp_to_datetime
|
||||
import simplejson
|
||||
|
||||
def dump():
|
||||
pointers = []
|
||||
for u in UserProfile.objects.select_related("user__email").all():
|
||||
pointers.append((u.user.email, u.pointer))
|
||||
pointer = u.pointer
|
||||
if pointer != -1:
|
||||
pub_date = Message.objects.get(id=pointer).pub_date
|
||||
pointers.append((u.user.email, datetime_to_timestamp(pub_date)))
|
||||
else:
|
||||
pointers.append((u.user.email, -1))
|
||||
file("dumped-pointers", "w").write(simplejson.dumps(pointers) + "\n")
|
||||
|
||||
def restore(change):
|
||||
for (email, pointer) in simplejson.loads(file("dumped-pointers").read()):
|
||||
for (email, timestamp) in simplejson.loads(file("dumped-pointers").read()):
|
||||
u = UserProfile.objects.get(user__email__iexact=email)
|
||||
if timestamp == -1:
|
||||
pointer = -1
|
||||
else:
|
||||
pointer = Message.objects.filter(
|
||||
pub_date__gte=timestamp_to_datetime(timestamp)).order_by("id")[0].id
|
||||
print "%s: pointer %s => %s" % (email, u.pointer, pointer)
|
||||
if change:
|
||||
u.pointer = pointer
|
||||
|
|
Loading…
Reference in New Issue