~unity-2d-team/unity-2d/Shell-MultiMonitor

« back to all changes in this revision

Viewing changes to grackle/server/model.py

  • Committer: William Grant
  • Date: 2012-01-22 07:10:23 UTC
  • Revision ID: william.grant@canonical.com-20120122071023-kwq8o5fvm6q9beys
Support batching.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
            'subject': message['subject'],
102
102
            }
103
103
 
104
 
    def get_messages(self, archive_uuid, count, order):
 
104
    def get_messages(self, archive_uuid, order, count, start):
105
105
        if order in ("date", "-date"):
106
106
            reversed = order[0] == '-'
107
107
        else:
108
108
            raise AssertionError("Unsupported order.")
109
 
        ids = self.archive_messages.get(
110
 
            archive_uuid, column_count=count,
111
 
            column_reversed=reversed).values()
112
 
        messages = self.messages.multiget(ids)
113
 
        return [self._format_message(messages[id]) for id in ids]
 
109
        pairs = self.archive_messages.get(
 
110
            archive_uuid, column_count=count+1,
 
111
            column_start=start, column_reversed=reversed).items()
 
112
        ids = [v for k, v in pairs]
 
113
        messages = self.messages.multiget(
 
114
            ids, columns=['date', 'from', 'subject'])
 
115
        actual_count = len(pairs)
 
116
        if len(pairs) > count:
 
117
            assert len(pairs) == count + 1
 
118
            actual_count -= 1
 
119
            next_memo = str(pairs[count][0])
 
120
        else:
 
121
            next_memo = None
 
122
        return (
 
123
            [self._format_message(messages[id]) for id in ids[:actual_count]],
 
124
            next_memo,
 
125
            )