113
113
'date': message.get('date'),
114
114
'from': message.get('from'),
115
115
'subject': message.get('subject'),
116
'message-id': message.get('message-id'),
119
def get_messages(self, archive_uuid, order, count, memo):
118
def get_messages(self, archive_uuid, order, count, start):
120
119
if order in ("date", "-date"):
121
120
reversed = order[0] == '-'
123
122
raise AssertionError("Unsupported order.")
125
memo = uuid.UUID(memo)
126
# Get up to n+1 messages from the memo: the last item of the
127
# previous batch (because that's where the memo starts) + this
129
123
pairs = self.archive_messages.get(
130
124
archive_uuid, column_count=count + 1,
131
column_start=memo, column_reversed=reversed).items()
133
if memo and len(pairs) and pairs[0][0] <= memo:
135
elif len(pairs) > count:
139
return (None, [], None)
141
assert 0 < len(pairs) <= count
125
column_start=start, column_reversed=reversed).items()
143
126
ids = [v for k, v in pairs]
144
127
messages = self.messages.multiget(
145
ids, columns=['date', 'from', 'subject', 'message-id'])
128
ids, columns=['date', 'from', 'subject'])
129
actual_count = len(pairs)
130
if len(pairs) > count:
131
assert len(pairs) == count + 1
133
next_memo = str(pairs[count][0])
149
[self._format_message(messages[id]) for id in ids],
137
[self._format_message(messages[id]) for id in ids[:actual_count]],